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
2
votes
1 answer

Configuring Johnny Cache

I'm trying to set up Johnny Cache on my dev machine but am running into some issues. Using the file based cache like this: CACHES = { 'default' : dict( BACKEND= 'johnny.backends.filebased.FileBasedCache', LOCATION= '/tmp', …
Kit Sunde
  • 35,972
  • 25
  • 125
  • 179
2
votes
2 answers

Does `cache.set()` use `version=1` by default instead of `version=None` in Django?

If I only set and get David with version=0, then I can get John and David in order as shown below. *I use LocMemCache which is the default cache in Django and I'm learning Django Cache: from django.core.cache import cache cache.set("name",…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
2
votes
1 answer

Django Redis cache get TTL (expire time)

Is it possible to get key's expire time in Django using Redis cache? Something like: from django.core.cache import cache cache.get_expire('mykey') # 300 (seconds) I tried: cache.ttl('my_key') getting an error AttributeError: 'RedisCache'…
2
votes
1 answer

Django multiple caches backends

I want to use multiple caching engines in one django project. In example I use sorl.thumbnail, that generated many sql queries to get/set thumbnail for model image. For caching this queries I use memcached backend. But, other caches stopped working,…
Igor
  • 479
  • 5
  • 13
2
votes
0 answers

django 3.0.2 get_cache_key returns different cache keys

I'm trying to invalidate a view following this Expire a view-cache in Django?. Here's a view function where I have disabled per-site caching and enabled per-view caching. This is the view, say, that I need to…
Azima
  • 3,835
  • 15
  • 49
  • 95
2
votes
2 answers

Django : make a variable persistent

Basically I want to make a variable persitent in Django and I don't know how. To be more precise, I want a user to choose a specific project when he logs in the site (via a ChoiceField for example). Then, for as long as he does not select another…
2
votes
0 answers

Django MPTTModel Tree structure gets corrupted inside Redis Cache upon concurrent creation and retrieval operations

Usecase: We've got a case where one of our models Content represents hierarchical data for our organization and for maintaining this hierarchy we've used django-mptt package which is based on the Modified Preorder Tree Transversal algorithm and for…
nick
  • 439
  • 1
  • 4
  • 17
2
votes
0 answers

Why Django memcached always return none?

I have 2 different cache type as follow: (I am using MySQL connector because the client wants it like this.) import os,sys from pathlib import Path sys.path.append(os.path.dirname(os.path.abspath('.'))) os.environ['DJANGO_SETTINGS_MODULE'] =…
Murat Demir
  • 716
  • 7
  • 26
2
votes
0 answers

Django progressive web app gives an error in all browsers after caching files

I was following this tutorial to make my website a PWA website using django-progressive-web-app. However, when I opened the app from firefox I get the following error: Oops. The site at http://localhost:8000/ has experienced a network protocol…
user14387653
2
votes
1 answer

Error accessing AWS elasticache redis in cluster mode) + TLS Enabled from django service

I'm trying to connect AWS elasticache(redis in cluster mode) with TLS enabled, the library versions and django cache settings as below ====Dependencies====== redis==3.0.0 redis-py-cluster==2.0.0 django-redis==4.11.0 ======settings======= CACHES =…
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

Cache in only in Django (as database caching) and not in browser

I've tried a lot of things, and they all failed. My Django (2.0) website has some pages which take a lot of time to generate. I want to keep this pages in the database cache of the Django server until the database changed. My goal: Have pages ready…
2
votes
1 answer

I want to cache Django database objects without changing every single line that does a DB lookup

Short Version: In Django (ideally Django 1.7), I want to read certain database objects just once each day at 2 AM and cache them. Each time I do MyModel.objects.get() it will not touch the database, it will use the cache. Then I will manually…
SerMetAla
  • 4,332
  • 5
  • 31
  • 25
2
votes
1 answer

DRF, caching for as_view()?

In my view, I often use APIView's as_view() to generate json. I'd like to cache the response and tried the following but it won't work def some_complex_view(self, request, *args, **kwargs): pass @method_decorator(cache_page(60,…
eugene
  • 39,839
  • 68
  • 255
  • 489
2
votes
2 answers

Don't refill Django forms with Browser Back Button

I'm asking a question and the answer could help me a lot. When I'm filling my Django form, I press a validate button in order to store data form. Then, I am redirected on a new page (form resume page, home page, ...). But in my browser, if I click…
Essex
  • 6,042
  • 11
  • 67
  • 139