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.46k stars 195 forks source link

Go 1.18 generics support? #134

Closed vikstrous2 closed 2 years ago

vikstrous2 commented 2 years ago

Have you considered adding support for generics to remove the need for casting when using the cache? I think a change like that would have to be a new major version, but I think that it would make using the cache much nicer. I don't know the implications for the stores interface. I would have to experiment a bit to understand the implications. I think this would be a fun little project, so I'm open to making the PR :)

eko commented 2 years ago

Hi,

I just merged on master a first implementation of generics for CacheInterface so you have to instantiate cache the following way now:

cacheManager := cache.NewChain[any](
    cache.New[any](ristrettoStore),
    cache.New[any](redisStore),
)

Of course, you can declare your own type instead or any, that’s generics behavior ;-)

Please feel free to comment if you have any issue.

eko commented 2 years ago

Closing this issue since v3 has been released. Thank you