1. Jannis Leidel
  2. johnny-cache


Jason Moiron  committed 01c126b Merge

Merged in akaihola/johnny-cache (pull request #8)

  • Participants
  • Parent commits 629145f, d44f5b1
  • Branches default

Comments (0)

Files changed (2)

File docs/index.rst

View file
 Johnny does not define any views, urls, or models, so we can skip adding it
+*Note*: Johnny is *not* enabled by default in scripts, management commands,
+asynchronous workers and the shell.  See `the queryset cache documentation
+for instructions on how to enable it in these cases.
 New in this version

File docs/queryset_cache.rst

View file
 .. autofunction:: johnny.cache.invalidate
+Using with scripts, management commands, asynchronous workers and the shell
+Since the QuerySet Cache is enabled via middleware, queries made from outside
+of Django's request-response loop don't use Johnny. For example, saves and
+deletes don't invalidate models in management commands.
+You can enable the QuerySet Cache manually by instantiating the middleware in
+your code before using the ORM::
+    from johnny.middleware import QueryCacheMiddleware
+    qcm = QueryCacheMiddleware()
+    # do some work
+    qcm.unpatch() 
+    # this unpatches and flushes the cache
+To make sure Johnny is always active in management commands, you can enable it
+the project's ``__init__.py`` file::
+    cd /tmp
+    django-admin.py createproject myproject
+Now insert into ``/tmp/myproject/__init__.py``::
+    from johnny.middleware import QueryCacheMiddleware
+    QueryCacheMiddleware()
+This works because :func:`django.core.management.setup_environ` always imports
+the project module before executing the management command.