django-cache

Django caching with Redis

Django caching with Redis Question: I have implemented django caching using redis following this blog: https://realpython.com/caching-in-django-with-redis/ So I followed this, installed the package, Added in CACHES = { “default”: { “BACKEND”: “redis_cache.RedisCache”, “LOCATION”: “redis://127.0.0.1:8000/”, “OPTIONS”: { “CLIENT_CLASS”: “django_redis.client.DefaultClient” }, “KEY_PREFIX”: “example” } } Then in views. from django.conf import settings from django.core.cache.backends.base import DEFAULT_TIMEOUT from …

Total answers: 2

Django delete cache with specific key_prefix

Django delete cache with specific key_prefix Question: I’m using Django’s per-view @cache_page decorator and have set a different key_prefix for each view. I’ve previously deleted the cache with: from django.core.cache import cache cache.clear() But what if I just want to delete the keys containing a specific key_prefix? I can obviously do it by just connecting …

Total answers: 3

Django default cache

Django default cache Question: I’m importing and using cache as this: from django.core.cache import cache cache.add(‘a’,’b’,60) I haven’t defined any settings for the cache in settings.py ,then where does this cache come from and where is it stored. Django documentation says: "This object is equivalent to caches[‘default’]", but what is the default ? Asked By: …

Total answers: 3

Clearing specific cache in Django

Clearing specific cache in Django Question: I am using view caching for a django project. It says the cache uses the URL as the key, so I’m wondering how to clear the cache of one of the keys if a user updates/deletes the object. An example: A user posts a blog post to domain.com/post/1234/ .. …

Total answers: 4

Global variable/Variable caching in Django

Global variable/Variable caching in Django Question: In my website, I want to present to the user the most viewed product categories in a sidebar, in multiple pages. so in each different view I have: variables = RequestContext(request, { (…) ‘most_viewed_cats’: calculate_most_viewed_categories() } and in the various templates {% include "list_most_viewed_categories" %} and in that one: …

Total answers: 1