Multiple cache definitions all pointing to the same Redis instance. Is this okay?

19 views
Skip to first unread message

EJ

unread,
Sep 8, 2015, 12:34:18 PM9/8/15
to Django users
Hi,

I'm still learning about Django's caching features and had a question about my specific setup.  My app uses a Redis-backed cache to store a variety of different data (including sessions, users, and other stuff).

In settings.py, I've defined several caches, as shown below.  These all point to the exact same Redis instance.  I've set it up like this because I really like the ability to set a VERSION for a specific subset of keys.  As the structure of the cached data changes in development, I can invalidate a whole set of cached keys just by bumping up the VERSION setting.  Or at least that's my idea right now.  I'm basically using cache definitions just to group keys.

Is it okay to do this?  On every request, the app hits several of these "caches".  Am I inadvertently opening up multiple connections to the same Redis instance on every page view?  Are there any other downsides to this kind of setup?  Or alternative ways of 'versioning' groups of keys?

Thanks in advance.

- EJ

CACHES = {
'default': {
"VERSION": 1,
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0",
"KEY_PREFIX" : "d",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
'sessions': {
"VERSION": 1,
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0",
"KEY_PREFIX" : "s",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
'users': {
"VERSION": 1,
"BACKEND": "django_redis.cache.RedisCache",
"LOCATION": "redis://127.0.0.1:6379/0",
"KEY_PREFIX" : "u",
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
}
},
...
}
Reply all
Reply to author
Forward
0 new messages