[Answer]-Is it a good idea to store in cache a dict of my app's cache

1👍

It’s hard to give you a satisfying answer without knowing the specifics of your application. With that in mind…

This can be an acceptable solution; however keep in mind that objects can be evicted from memcached before their expiry date, in which case you’d lose your key index.

Depending on your specific use case, this limitation can be acceptable or not.

An approach that may serve you better is to be clever about how your name your keys; for example, if your application deals with books, you could cache various data under names such as book.<id>.author, book.<id>.title, etc. This way, if you need to invalidate all the data for the book with id 42, you could just generate all the cache names you need to invalidate (book.42.author, book.42.title, etc.) and delete those.

Leave a comment