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",
}
},
...
}
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/08897b49-2dbb-470f-aed6-3dca7482445c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment