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.4k stars 193 forks source link

Can I get all cached entities? #217

Closed holenlv closed 10 months ago

holenlv commented 1 year ago

I want to foreach all cached entities, Is there a solution?

eko commented 10 months ago

Hi,

Unless most of cache stores are key/value ones, this cannot be done.

Gocache only brings an interface to all stores but nothing is stored in memory.

In your case, you should keep a key containing all the keys you wrote in your store in order to be able to retrieve them all. Using Redis you can use sets for this.

Hope it helps. Closing this as there is no issue with gocache library here.