muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

I hope to provide a method: get the value but not update the expiration time

sirodeneko opened this issue · comments

I hope to provide a method: get the value but not update the expiration time

If you are busy, I can do it。

Same. go-cache can get a value without updating the exp time, but it cannot be set to update after each access. I need the two features both.

Hello all. I also need the function that the value is forced to be deleted after timeout.

func (table *CacheTable) Add(key interface{}, lifeSpan time.Duration, data interface{}) *CacheItem {
func (table *CacheTable) AddWithTTL(key interface{}, ttl time.Duration, data interface{}) *CacheItem {

Ok, for the first time we can flush the complete cache. => as a work-a-round

var internalCache *cache2go.CacheTable

func init() {
	internalCache = cache2go.Cache("internalCache")
	go func() {
		for {
			time.Sleep(1 * time.Minute)
			internalCache.Flush()
		}
	}()
}

@sirodeneko @dreamblack86 Happy to review a PR for this!