[Django]-Django – Johnny Cache for multiple processes

4πŸ‘

βœ…

It appears that middleware is not called when you run scripts/management comands which is why you are seeing the difference. This makes sense when reading the documentation on middleware because it processes things like request and views, which don’t exist in a custom script.

I found a way around this, and there is an issue regarding it in the Johnny Cache bitbucket repo. In your script put the following before you do anything with the database:

from johnny.middleware import QueryCacheMiddleware
qcm = QueryCacheMiddleware()

# put the code for you script here

qcm.unpatch()

You can see more on that here:

https://bitbucket.org/jmoiron/johnny-cache/issue/49/offline-caching

and here:

https://bitbucket.org/jmoiron/johnny-cache/issue/50/johhny-cache-not-active-in-management

πŸ‘€joshcartme

3πŸ‘

That is the recommended way from the documentation:

from johnny.cache import enable
enable()

Update:

What I observed, as if your tasks.py files have this in the beginning, you can not disable johnny cache using settings.py anymore.

I have reported the issue: https://github.com/jmoiron/johnny-cache/issues/27

πŸ‘€hurturk

Leave a comment