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

GetIfPresent not return cached value at once #7

Closed qfrank closed 4 years ago

qfrank commented 6 years ago
        c := cache.New(cache.WithMaximumSize(1))
    k := "hello"
    c.Put(k, "world")

    fmt.Println(c.GetIfPresent(k))

    time.Sleep(time.Second)

    fmt.Println(c.GetIfPresent("hello"))

        //output
        //<nil> false
        //world true

this output result don't like real google guava cache

nqv commented 6 years ago

Currently, It writes to cache asynchronously so you might not get it from cache immediately. Sorry for the inconvenience. I'll see if anything I can do to fix this.

tony2001 commented 4 years ago

Yeah, you should really mention in the docs, this kind of behavior is definitely not what one would expect from a cache.

nqv commented 4 years ago

I believe this is fixed in https://github.com/goburrow/cache/commit/ed586e32006b30416a68137394a5f27d374c6eb0