Skip to content Skip to sidebar Skip to footer

How To Name/arrange My Memcached Keys When I Have Django Objects With Multiple Foreign Keys?

I have an existing Django app that doesn't do any Database caching. I am working to implement memcached to get a performance boost and reduce the amount of expensive database hits.

Solution 1:

Caching requires a solid and carefully crafted strategy because you might end doing things worse than they are. In most of the projects you actually don't need advanced caching. Why don't you cache the page and delete the page cache each time your DB is updated? this will allow the query to run once but the rest of the times the cache will be retrieved. If you still insist for caching, cache using a unique key, they key combination could be created by the unique objects id and the name of it. Signals are the way to go either way, if you update or create and new object delete the cache, but as you can see from your own example, a page cache is way more easily treated than going through a large number of objects. Apart from that, why don't you use the build in Django cache.get, cache.set, cache.delete function? this way you keep compatibility of your project and decouple your code from the cache engine (maybe tomorrow redis will be more preferred to your needs).


Post a Comment for "How To Name/arrange My Memcached Keys When I Have Django Objects With Multiple Foreign Keys?"