Jason Moiron avatar Jason Moiron committed 0ac1ac8

alter pull req #8 a bit to fit in with the enable/disable convenience functions

Comments (0)

Files changed (2)

 .. highlight:: python
-A typical ``settings.py`` file configured for ``johnny-cache``::
+A typical ``settings.py`` file for Django 1.3 configured for ``johnny-cache``::
     # add johnny's middleware
-*Note*: The above configuration is for Django 1.3, which radically changed
-its cache configuration.  To see a full inspection of options for earlier
-versions of Django please see the `queryset cache <queryset_cache.html>`_
+For a full inspection of options for earlier versions of Django please see 
+the `queryset cache <queryset_cache.html>`_ docs.
 The ``MIDDLEWARE_CLASSES`` setting enables two middlewares:  the outer one
 clears a thread-local dict-like cache located at ``johnny.cache.local`` at
 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
+*Note*: Since Johnny is enabled by the inclusion of middleware, it will not
+be enabled by default in scripts, management commands, asynchronous workers,
+or the django shell.  See `the queryset cache documentation
 for instructions on how to enable it in these cases.


 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.
+of Django's request-response loop will neither be cached nor used to invalidate
+the cache.  This can lead to stale data persisting in the cache.
-You can enable the QuerySet Cache manually by instantiating the middleware in
-your code before using the ORM::
+You can enable and disable the QuerySet Cache by using the convenience
-    from johnny.middleware import QueryCacheMiddleware
-    qcm = QueryCacheMiddleware()
+.. autofunction:: johnny.cache.enable
-    # do some work
+.. autofunction:: johnny.cache.disable
-    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``::
+Now, in ``myproject/__init__.py``::
-    from johnny.middleware import QueryCacheMiddleware
-    QueryCacheMiddleware()
+    from johnny.cache import enable
+    enable()
-This works because :func:`django.core.management.setup_environ` always imports
+This works because ``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.