eko / gocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches
https://vincent.composieux.fr/article/i-wrote-gocache-a-complete-and-extensible-go-cache-library/
MIT License
2.5k stars 199 forks source link

Get method doesn't work correctly for bigcache with string type. #166

Open ByungJun25 opened 2 years ago

ByungJun25 commented 2 years ago

Description Hi,

Thank you for making the awesome library first.

The type casting code is wrong for bigcache with string type. Because bigcache always returns []byte type(refer here) even though we can store data as string type.

I think it is better if type casting is failed, it should return not only zero value but also error.

Steps for Reproduction

  1. Set up Bigcache with string type

    func fn(config Config) {
    bigcacheClient, _ := bigcache.NewBigCache(bigcache.DefaultConfig(config.ExpiredTime))
    bigcacheStore := store.NewBigcache(bigcacheClient)
    
    memoryCache = cache.New[string](bigcacheStore)
    }
  2. Set data
    val := "some string data"
    memoryCache.Set(ctx, key, val) // There is no error because it will be convert to byte array
  3. Get data
    val, _ := memoryCache.Get(ctx, key) // There is no error but data is blank string.

Expected behavior: It should be return stored string data.

Actual behavior: It returned blank string.

Platforms: Ubuntu

Versions: v3.1.1

davidwudv commented 2 years ago

same issue