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
4
votes
4 answers

Will Django's cache modules work on Google App Engine?

I am running Django (1.0.2) on Google App Engine, and would like to know which (if any) of the following Django caching modules ought to inherently work with Google's memcache…
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
4
votes
1 answer

Django Database Caching

I'm working on a small project, and I wanted to provide multiple caching options to the end user. I figured with Django it's pretty simplistic to swap memcached for database or file based caching. My memcached implementation works like a champ…
f4nt
  • 2,661
  • 5
  • 31
  • 35
4
votes
2 answers

cannot concatenate 'str' and 'tuple' objects - Django - johnny cache

I try to install johnny cache with my django website. So i set up all the johnny cache related settings like this: CACHES = { 'default': { # 'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache', …
renard
  • 1,368
  • 6
  • 20
  • 40
3
votes
1 answer

Can I force Django’s per-site cache to use only each page’s path as its key?

I’ve developed a Django site. There’s pretty much a 1-to-1 relationship between model instances in the dabatase, and pages on the site. I’d like to cache each page on the site (using memcached as the cache back-end). The site isn’t too big —…
Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
3
votes
1 answer

How can explicitly reset a template fragment cache in Django?

I am using Memcache for my Django application. In Django, developers can use template fragment caching to only cache a section of a template. https://docs.djangoproject.com/en/dev/topics/cache/#template-fragment-caching I was wondering if there is a…
dangerChihuahua007
  • 20,299
  • 35
  • 117
  • 206
3
votes
1 answer

Wrap python decorator with another decorator

I have a common decorator call throughout my Django codebase: @override_settings( CACHES={ **settings.CACHES, "default": generate_cache("default", dummy=False), "throttling": generate_cache("throttling", dummy=False), …
Johnny Metz
  • 5,977
  • 18
  • 82
  • 146
3
votes
1 answer

Django cache_page - prepopulate/pre-cache

I have one DB query that takes a couple of seconds in production. I have also a DRF ViewSet action that returns this query. I'm already caching this action using…
Milano
  • 18,048
  • 37
  • 153
  • 353
3
votes
1 answer

Django MemcacheUnexpectedCloseError and [WinError 10061] No connection could be made because the target machine actively refused it

Hi I am new at django and trying to use django-cache to speed up page load that will list out 100 companies and their details per page but I am constantly running into errors. When I use the IP and Port from the django doc 127.0.0.1:11211 I get this…
RAFIN KHAN
  • 65
  • 6
3
votes
1 answer

Is it okay to use the same Redis store for both cache and django-channels channel layer in Django?

I have a Django 3.1 app that uses Redis for its cache backing store (django-redis). I wish to use django-channels, which has the ability to use Redis for channel layers. Is it safe or unsafe to use the same Redis store for both the cache and the…
sunw
  • 535
  • 5
  • 29
3
votes
1 answer

Django Cache - Update when model changed

I can't seem to find any tutorial on how to do this. So, I basically want to add caching to my Django project. I made a blog view, that should be cached and updated only if the model got changed since last caching. How do I do this?
Myzel394
  • 1,155
  • 3
  • 16
  • 40
3
votes
4 answers

django fragment caching for anonymous users only

I want to use django fragment caching for anonymous users, but give authenticated users fresh data. This seems to work fine: {% if user.is_anonymous %} {% load cache %} {% cache 300 "my-cache-fragment" %} I have to write this out…
asciitaxi
  • 1,369
  • 1
  • 16
  • 16
3
votes
1 answer

Django database cache TIMEOUT - make backend delete row

I'm not sure what Django database cache does with expired entries but it seems that they remain in the database. I want Django to delete them after they expire because their size is huge and there can be unlimited number of different keys. CACHES…
Milano
  • 18,048
  • 37
  • 153
  • 353
3
votes
1 answer

How to invalidate several django cached values efficiently?

TLDR Is there a way to mark cached values so I could do something like: cache.filter('some_tag').clear() Details In my project I have the following model: class Item(models.Model): month = models.DateField('month', null=False, blank=False,…
Danilo Favato
  • 283
  • 1
  • 11
3
votes
1 answer

Django cache loses keys

I have a Django installation that uses the FileSystem caches. The caching system is used by an array of different views. Putting in place various logs to log when a key is not found in the cache and hence regenerated, I've found out that often the…
pistacchio
  • 56,889
  • 107
  • 278
  • 420
3
votes
1 answer

Django Redis cache values

I have set the value to Redis server externally using python script. r = redis.StrictRedis(host='localhost', port=6379, db=1) r.set('foo', 'bar') And tried to get the value from web request using django cache inside views.py. from…
Karesh A
  • 1,731
  • 3
  • 22
  • 47