Jason Moiron avatar Jason Moiron committed 01c126b Merge

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

Comments (0)

Files changed (2)

 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


 .. 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.
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.