package com.icloud.server.scala.engine.cache

import javax.annotation.{PostConstruct, PreDestroy}

/**
 * @Author : yang
 * @Date : 2022-07-14 00:14
 * @Version : 2.1.2
 */


abstract class AbstractCache[T] {
  @volatile protected  var cache: java.util.Map[String, T] = null

  @PostConstruct def init ={
    cache = buildCache
  }

  @PreDestroy def clear =  {
    cache.clear()
  }

  def buildCache: java.util.Map[String, T]

  def getCache: java.util.Map[String, T] = {
    return cache
  }

  def get(key: String): T = {
    return cache.get(key)
  }
}
