Beyond the SQL: Cacheing: Watching your cache

  1. When to worry about cacheing?
  2. Cacheing

Determining the right number of max_entries can be tricky. In this simple example, we know exactly how many entries we’ll be caching per post, but in a more complex setup we might only be able to guess. So it’s useful to watch the cache fill up, especially immediately before and after loading a page.

Go to the command line and cd into your Blog folder (the same folder that has “manage.py” in it).

$ python manage.py shell

>>> from django.core.cache import cache

>>> cache._max_entries

500

>>> cache._num_entries

14

Visit a new page, and you should see the number change:

>>> cache._num_entries

15

It’s important, if you have a complex system, to ensure that the maximum number of cache entries is significantly greater than the number of cache entries used per page view.

  1. When to worry about cacheing?
  2. Cacheing