19

I've installed django-redis-cache and redis-py. I've followed the caching docs for Django. As far as I know, the settings below are all that I need. But how do I tell if it's working properly??

settings.py

    CACHES = {
        'default': {
            'BACKEND': 'redis_cache.RedisCache',
            'LOCATION': '<host>:<port>',
            'OPTIONS': {
                'DB': mydb,
                'PASSWORD': 'mydbspasswd',
                'PARSER_CLASS': 'redis.connection.HiredisParser'
            },
        },
    }

...

    MIDDLEWARE_CLASSES = (
        'django.middleware.cache.UpdateCacheMiddleware',
         ...[the rest of my middleware]...
        'django.middleware.cache.FetchFromCacheMiddleware',
    )

    CACHE_MIDDLEWARE_ALIAS = 'default'
    CACHE_MIDDLEWARE_SECONDS = (60 * 60)
    CACHE_MIDDLEWARE_KEY_PREFIX = ''
Community
  • 1
  • 1
Matt Parrilla
  • 3,171
  • 6
  • 35
  • 54
  • 2
    What are you asking that you can't find out by testiong it out? – James Khoury Oct 06 '11 at 01:36
  • 1
    How can I test and tell if it worked? I'm a total caching newb! – Matt Parrilla Oct 06 '11 at 14:00
  • 1
    I just changed the wording of my question. I suppose it really makes it a different question, but it better articulates what I need to figure this out! – Matt Parrilla Oct 06 '11 at 19:44
  • Yes your question now makes a lot more sense. I don't know much about Redis but I would test speeds of setting and getting with and then without Redis. That should show you how much speed increase you are getting with it. – James Khoury Oct 06 '11 at 22:35
  • Also check out the great advice at: http://stackoverflow.com/questions/3801379/how-can-i-use-redis-with-django – James Khoury Oct 06 '11 at 23:02
  • @James, do you have a link to a good resource for learning how to perform speed tests on your site? This is my first production quality site (hopefully it's production quality!). I realize this is now no longer the question... but it would help!! – Matt Parrilla Oct 11 '11 at 03:44
  • I don't have any links but i would suggest looking into pythons cProfile – James Khoury Oct 11 '11 at 05:12
  • 1
    Actually a quick search got me : https://code.djangoproject.com/wiki/ProfilingDjango – James Khoury Oct 11 '11 at 05:13
  • Great! Thank you. I didn't even really know what to search for, so it's a big help!! – Matt Parrilla Oct 11 '11 at 18:26

3 Answers3

65

Didn't work with Django yet, but here's my default approach for checking if some component actually writes to redis during development:

First, I flush all keys stored in redis in order to remove old cache entries (never do this in production as this removes all data from redis):

> redis-cli FLUSHALL

Then activate caching in my application, and see what redis does:

> redis-cli MONITOR

You should enter an interactive session where you see every command sent to redis.

Reload your page and on your terminal you should see some SET* operations storing the cache data.

Reload again and if your cache works, you should see some GET* operations retrieving the cached data.

Note: with this method you can check if your cache is actually used. What you can't see is if your cache helps speeding up your application. For that you have to do performance tests as suggested in the comments.

cngzz1
  • 143
  • 2
  • 9
Max
  • 15,693
  • 14
  • 81
  • 131
10

You could install the django-debug-toolbar and see if the number of queries decreases when you enable caching. Though I don't think this is the best solution to the posed question, I still think you want to do this, as you can easily pinpoint costly queries using this setup, and then add the appropriate caching to them.

markijbema
  • 3,985
  • 20
  • 32
2

Usage of Redis has been focused on lowering the overall query load to the database.

This system likes to work independetly without any coflict ;)

I suggest don't worry about its operation and don't change its configs if you can see its activities at:

> redis-cli MONITOR

And there is some elements about your code.