1. Jason Moiron
  2. johnny-cache
Issue #50 wontfix

johhny-cache not active in management command

Anonymous created an issue

I've got a site that I'm using johnny-cache on. I have a management command which retrieves data from twitter and creates database records (via ORM) for them. When I go view the admin page for the Tweet model, I do not see new results. Disabling johnny-cache fixes this.

Since johnny-cache is applied via middleware, it seems that anything happening from script/management command will be outside of johnny-cache's knowledge and will result in stale data being served.

Comments (1)

  1. Jason Moiron repo owner

    An easy way to make sure johnny is always active (in shell sessions, management commands, etc) is to enable it manually (see https://bitbucket.org/jmoiron/johnny-cache/issue/49/offline-caching) in manage.py.

    If you want only management commands to be patched, it's a little weirder. Jeremy wrote this code which goes in an init.py file somewhere and inspects the stack to see if a management command is active, then enables johnny:

    from django.conf import settings
    from johnny.cache import get_backend
    import sys
    import traceback
    if [i for i in traceback.extract_stack() if 'django/core/management' in i[0]] \
       and 'test' not in sys.argv:
        if not getattr(settings, 'DISABLE_JOHNNY_PATCH', False):

    In general, I don't really want Johnny to attempt to insert itself at some earlier level in Django; I want to maintain the ability to turn it off by disabling the middleware, where "off" means "do not patch anything." The last thing I want to do is have a bug where Johnny is patched but in some other way "disabled", and have that somehow impact the performance or correctness of the ORM.

  2. Log in to comment