muesli / cache2go

Concurrency-safe Go caching library with expiration capabilities and access counters
Other
2.11k stars 518 forks source link

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

Open sirodeneko opened 2 years ago

sirodeneko commented 2 years ago

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

sirodeneko commented 2 years ago

If you are busy, I can do it。

HansenH commented 2 years ago

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.

dreamblack86 commented 2 years ago

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 {
dreamblack86 commented 2 years ago

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()
        }
    }()
}
muesli commented 2 years ago

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