Questions tagged [django-caching]

django-caching refers to the Django cache system

django-caching refers to the Django cache system.

Quote from docs:

Django comes with a robust cache system that lets you save dynamic pages so they don’t have to be calculated for each request. For convenience, Django offers different levels of cache granularity: You can cache the output of specific views, you can cache only the pieces that are difficult to produce, or you can cache your entire site.

57 questions
3
votes
1 answer

Python-Django Caching images

So i have read the Django-Docs about caching and understood i can cache data per view which is what i want to do. I have a URL like this : www.mysite.com/related_images/{image_id}. which calculates related images for the selected {image_id} and…
Ethan
  • 261
  • 5
  • 16
3
votes
2 answers

Django-Cache Testing

Since i'm new to django-cache, I was trying to cache a particular view in Django. I'm not sure whether the data is fetched from cache or from the database. How do I verify that? Being a newbie, kindly also check that I'm caching the view correctly…
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
2
votes
1 answer

Changes in DB data not reflecting in the Django queryset in a continuously looping script

I am using Django's ORM to get newly added entries from a Db and pass them to a Messaging queue. I am doing this in an infinite while loop , The PROBLEM in every loop iteration I am getting the same queryset even when I have added/deleted/edited…
PKaura
  • 199
  • 3
  • 9
2
votes
0 answers

Django cached template loader: exclude template from cache, or clear cache without restart

I use Django's cached template loader to speed up my site: TEMPLATE_LOADERS = ( ('django.template.loaders.cached.Loader', ( .... )), ) Is there a way to exclude specific templates from being cached? I have a template that I change a…
user984003
  • 28,050
  • 64
  • 189
  • 285
2
votes
0 answers

Caching per-app in Django rather than per-site or per-view

Lets say I have two apps in my Django website one for the API and one for the html pages, all urls starting with /api/ are handled by the API app. I have setup two caches with a specific setup for each like so: CACHES = { 'default': { …
2
votes
1 answer

CSRF error when using a cached response

I am doing some aggressive caching and this results in a CSRF error when I use a previously cached old response. Is there a way to just refresh the csrf token inside the cached response? Unable to understand the Caching section in…
sureshvv
  • 4,234
  • 1
  • 26
  • 32
2
votes
5 answers

How to get expiration time from cache in Django?

With django.core.cache.backends.locmem.LocMemCache this worked: key = cache.make_key('foo') cache.validate_key(key) t = cache._expire_info.get(key) But it breaks with django.core.cache.backends.memcached.MemcachedCache I get error:…
petr0
  • 411
  • 7
  • 10
2
votes
1 answer

How does Django cache system works?

How does Django cache system works?
Aventador
  • 205
  • 2
  • 11
1
vote
4 answers

`dir()` doesn't show the cache object attributes in Django

I can use these cache methods set(), get(), touch(), incr(), decr(), incr_version(), decr_version(), delete(), delete_many(), clear() and close() as shown below: from django.core.cache import cache cache.set("first_name",…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
1
vote
1 answer

How to get the contents of the cache properly in Django?

I set 4 cache values with LocMemCache as shown below: from django.core.cache import cache cache.set("first_name", "John") cache.set("last_name", "Smith", version=2) cache.set("age", 36, version=3) cache.set("gender", "Male") Then, I tried to see…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
1
vote
1 answer

Django on the production server (nginx + gunicorn), after changes in the files, sometimes the changes are displayed, sometimes they are not displayed

On the production server (nginx + gunicorn), after changes in the files, sometimes the changes are displayed, sometimes they are not displayed. After restarting the server, everything works correctly. I thought it might be related to caches and…
1
vote
0 answers

Django memcache expire url

from django.core.cache import cache from django.http import HttpRequest from django.utils.cache import get_cache_key def expire_page(path): request = HttpRequest() request.path = path key = get_cache_key(request) if…
anoop
  • 49
  • 1
  • 3
1
vote
1 answer

Can't define default cache Django

I'm trying to setup caching in Django, but it won't let me define a default cache. I'm not overly concerned with what type of cache I use (I have tried Filesystem and Database Cache.) But even when copy + pasting their example code the error…
lux
  • 411
  • 7
  • 17
1
vote
1 answer

weak object has gone away? - python/django

I'm having this problem in my django project that I believe is related to caches. It appears once every 6 months or so and is "fixed" by restarting the app, only to come back some months later. Suddenly all views will fail with this…
Martin Massera
  • 1,718
  • 1
  • 21
  • 47
1
vote
1 answer

django cache key naming

I want to store some items using Django cache API. Are there are best practices to follow while naming the key. I know some people just give user name as the key. But I am going to cache various items in different views and having the same key every…