Questions tagged [django-cache]

Django includes a cache system that lets you save dynamic pages or page fragments so they don't have to be generated for each request.

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.

Django also works well with "upstream" caches, such as Squid and browser-based caches. These are the types of caches that you don't directly control but to which you can provide hints (via HTTP headers) about which parts of your site should be cached, and how.

See also:

248 questions
1
vote
1 answer

How to correctly set DummyCache for testing in Django?

I rely on my cache for my development interface. But when I run tests it distorts my cache. I was surprised how Django creates a new database for testing, but wouldn't create a new cache, but that's a different story. I did some research, and I…
John Mc
  • 331
  • 1
  • 3
  • 12
1
vote
0 answers

How to cache iframe in django

I am building a django app and one of my templates has a mapstore iframe on it. That iframe is kind of heavy. Is there any way to cahce that iframe, or all the template, i dont have to wait so long every time the page is loaded. this is the…
Ernesto Ruiz
  • 736
  • 9
  • 31
1
vote
1 answer

Problem with deleting cache in localized page

I have pages to view posts. Also I have header with option to switch language and when I switch language, it changes on all pages, except pages with cache. There language changes only when I reboot the server. I need to understand, how I can delete…
Steep 27
  • 35
  • 4
1
vote
0 answers

Is Django's Caching Framework per user or across all user's

I have read through Django's caching framework documentation (https://docs.djangoproject.com/en/3.1/topics/cache/#), and want to know if the caching is per user or for all user's. For example, User A: Generates this link with parameters -->…
anon
  • 77
  • 5
1
vote
1 answer

Is there a way to set an expiration time for a Django cache lock?

I have a Django 3.1.3 server that uses Redis for its cache via django-redis 4.12.1. I know that cache locks can generally be set via the following: with cache.lock('my_cache_lock_key'): # Execute some logic here, such as: …
sunw
  • 535
  • 5
  • 29
1
vote
1 answer

django-cacheops with aws redis Encryption

I have set up redis with Encyption in transit and rest. I have come across https://dev.to/yuki0417/easy-way-to-connect-to-amazon-elasticache-redis-with-password-from-django-app-40il and Connect to AWS ElastiCache with In-Transit Encryption. As I am…
shorif2000
  • 2,582
  • 12
  • 65
  • 137
1
vote
1 answer

Caching base.html only in Django

My base.html template, which is extended in nearly all of my pages, contains a header that I never want to be cached since it contains the username of the current user. I have two pages where it keeps getting cached though. I tried adding a {%…
thean
  • 97
  • 9
1
vote
2 answers

One to One vs field in same models django

I have created two templates I have the extended template De user (AbsctractUser) and the template (Score) with the field total_score. From what I could understand about the django cache with redis is that as long as the line is not modified, redis…
Pascal de Sélys
  • 127
  • 1
  • 10
1
vote
1 answer

Django query does not update when database changes

I have a weird problem, I think it comes from the cache between django and postgres but not so sure. I have multiple tables in database but the problem only happens with one of them. Let's say the SpeakingSession table. Everytime I make a change…
Trong Lam Phan
  • 2,292
  • 3
  • 24
  • 51
1
vote
2 answers

Django caching with Redis

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", …
Harshit verma
  • 506
  • 3
  • 25
1
vote
1 answer

Is it possible cache the whole page in Django?

I'm currently working this website. The problem is that the pages takes 3-4 seconds to get the first bye, and I think it's because query to load data in the pages is very slow. In the store page, it basically uses an object of a store to show the…
Jay P.
  • 2,420
  • 6
  • 36
  • 71
1
vote
2 answers

How to cache a view only for unauthenticated users?

I have a view which I want to cache only for unauthenticated users. The view should be something like this: @cache_page_for_guests(60 * 15) def my_view(request): I've looked at the docs but could not but could not find any hints about this.…
Milkyway
  • 705
  • 3
  • 12
  • 25
1
vote
1 answer

Django: how to cache dynamic pages flexibly?

I was trying to set up cache for my Django application but it seems that Django's caching framework is based on TIMEOUT: set a cache and it'll remain valid for the TIMEOUT amount of seconds. That seems pretty useless for most situations. Most…
Continuation
  • 12,722
  • 20
  • 82
  • 106
1
vote
2 answers

Cannot seem able to modify cache value from celery task

Description: I want to have a cached value (let's call it a flag) to know when a celery task finishes execution. I have a view for the frontend to poll this flag until it turns to False. Code: settings.py: ... MEMCACHED_URL =…
John Moutafis
  • 22,254
  • 11
  • 68
  • 112
1
vote
1 answer

Django staticgenerator vs CACHE_BACKEND

Is there any difference between staticgenerator and useing Django's CACHE_BACKEND on the filesystem eg. CACHE_BACKEND = 'file:///var/tmp/django_cache' ?
stapler
  • 201
  • 1
  • 7
  • 17