How can I set up a Django router to delegate caching between MySQL and memcached? See the sample configuration below:
CACHE_OPTIONS = {
'primary': {'ENGINE': 'django.core.cache.backends.db.DatabaseCache', 'TABLE': 'custom_cache'},
'secondary': {'ENGINE': 'django.core.cache.backends.memcached.PyMemcacheCache', 'HOST': '127.0.0.1:11212'},
}
DB_ROUTERS = ['custom_routers.PrimaryCacheRouter', 'custom_routers.SecondaryCacheRouter']
In my experience, properly configuring custom Django routers demands a thorough mapping of read and write operations to your specific caching backends. Implementing carefully designed db_for_read and db_for_write methods is crucial, ensuring that each operation correctly directs your caching requests to either the primary MySQL backend or the secondary memcached backend. I encountered challenges when operations overlapped, so isolating responsibilities in your router methods was essential. Thorough testing and refining these methods are indispensable for a robust and efficient cache delegation between different caching systems.
hey, i solved it by checking the op type in each router. i sent writes to mysql and reads to memcachd. a bit of logging helped catch any faulty route. maybe give that a try?
hey, have u tried addin a midleware layer to auto-detect the operation load? sometimes i think a hybrid strategy could help keep your mysql & memcachd in sync. anyone else tried something like this?