How can I confirm my Django views are being cached when I use the cache_page decorator like so:
@cache_page(60)
def my_view(request):
Ideally I would like to output cache hit/miss messages in the console so I can confirm my view is being cached for 60 seconds etc.
Many thanks, g
you could grab a copy of django-debug-toolbar
(http://github.com/robhudson/django-debug-toolbar) and watch the queries: if the page is not being pulled from the cache, django-debug-toolbar
should display all of the queries required to assemble your page. if the page is pulled from the cache, you won't see the queries.
you could also add logging to the particular cache wrapper that you're using, and then reference the output in django-debug-toolbar
's "logging" panel. heres an example of what that would look like: http://gist.github.com/242011
i'd also recommend grabbing a copy of django-memcache-status
(http://github.com/bartTC/django-memcache-status) and memcache-top
(http://code.google.com/p/memcache-top/), if you're interested in monitoring memcache usage in detail.
Depending on the cache middleware you are using, you could inspect the process_request
method of that class and find some line like these (taken from django/middleware/cache.py
)
131 response = cache.get(cache_key, None)
132 if response is None:
133 ...
... logging.debug("Cache miss")
...
... else:
... logging.debug("Cache hit")
and log the messages from there. I do admit, it is not a clean way to do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With