package gaf3.core.cache

import gaf3.core.cache.util.MemCache

class MemCacheService(val config: GafCacheConfigure) : CacheService {

    override fun getCache(key: String): String? {
        return memCache.getCache(key)
    }

    override fun setCache(key: String, value: String, expired: Long?) {
        val exp = expired ?: config.validitySec
        if(exp > 0) {
            memCache.setCache(key, value, System.currentTimeMillis() + exp * 1000)
        } else {
            memCache.setCache(key, value)
        }
    }

    override fun delCache(key: String) {
        memCache.delCache(key)
    }

    companion object {
        private val memCache = MemCache<String>()
    }
}