goburrow / cache

Mango Cache 🥭 - Partial implementation of Guava Cache in Go (golang).
BSD 3-Clause "New" or "Revised" License
580 stars 48 forks source link

Eviction not happening even after expiry time has passed #19

Closed rish8089dunzo closed 4 years ago

rish8089dunzo commented 4 years ago
/**
Above code is executed on server start, it initializes the loading cache instance
**/
handler.inMemCache=cache.NewLoadingCache(func(key cache.Key) (cache.Value, error){
        return "Loader func gets executed",nil
    },cache.WithMaximumSize(1000),
    cache.WithPolicy("lru"),
    cache.WithExpireAfterAccess(3*time.Second),
    cache.WithRefreshAfterWrite(3*time.Second))
type Handler struct {
    inMemCache cache.LoadingCache
}
/**
    It first checks the value in mem cache if its available or not, if available it picks up from there otherwise executes the loader function
**/
func (h *Handler) Get(c echo.Context) error{
    val,exists:=h.inMemCache.GetIfPresent("key")
    if(!exists) {
        r,_:=h.inMemCache.Get("key")
        return c.JSON(200,r)
    } else{
        return c.JSON(200, "returning from cache")
    }
}

Everything is working as expected but the key is not getting evicted after 3 seconds. How can we resolve this issue?

nqv commented 4 years ago

Thanks for reporting. Can you check it again with the latest commit? It still needs to handle XAfterWrite better though (need a new Writing queue that I'm still trying)

nqv commented 4 years ago

Hi, I give it a try in https://github.com/goburrow/cache/commit/4060fe738647abf6f1adbece2cd69c7fecb3e942 Would you please check out that version and let me know if this is not fixed?