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
93
votes
14 answers

How do you know if memcached is doing anything?

I'm testing out using memcached to cache django views. How can I tell if memcached is actually caching anything from the Linux command line?
MikeN
  • 45,039
  • 49
  • 151
  • 227
65
votes
10 answers

Redis Python - how to delete all keys according to a specific pattern In python, without python iterating

I'm writing a django management command to handle some of our redis caching. Basically, I need to choose all keys, that confirm to a certain pattern (for example: "prefix:*") and delete them. I know I can use the cli to do that: redis-cli KEYS…
alonisser
  • 11,542
  • 21
  • 85
  • 139
52
votes
1 answer

Difference between django-redis-cache and django-redis for redis caching with Django?

I noticed that there are two different projects for using redis for django cache https://github.com/sebleier/django-redis-cache/ https://github.com/niwibe/django-redis Is one better known than the other, more of a standard package? I can't decide…
aris
  • 22,725
  • 1
  • 29
  • 33
41
votes
12 answers

Get list of Cache Keys in Django

I'm trying to understand how Django is setting keys for my views. I'm wondering if there's a way to just get all the saved keys from Memcached. something like a cache.all() or something. I've been trying to find the key with cache.has_key('test')…
Brenden
  • 8,264
  • 14
  • 48
  • 78
35
votes
4 answers

How to clear the whole cache when using django's page_cache decorator?

I've got a pretty simple site where I'm using the page_cache decorator. I have a cronjob that checks for new data and processes it if it's available. (This is run using management commands executed with crontab) I want to then clear all the page…
monkut
  • 42,176
  • 24
  • 124
  • 155
28
votes
6 answers

How to use 2 different cache backends in Django?

I need to use memcached and file based cache. I setup my cache in settings: CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', 'LOCATION': 'c:/foo/bar', }, 'inmem': { …
robos85
  • 2,484
  • 5
  • 32
  • 36
26
votes
5 answers

Clearing specific cache in Django

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/…
Brenden
  • 8,264
  • 14
  • 48
  • 78
22
votes
7 answers

Per-request cache in Django?

I would like to implement a decorator that provides per-request caching to any method, not just views. Here is an example use case. I have a custom tag that determines if a record in a long list of records is a "favorite". In order to check if…
Chase Seibert
  • 15,703
  • 8
  • 51
  • 58
20
votes
3 answers

Django Cache cache.set Not storing data

When I run python manage.py shell and then: from django.core.cache import cache cache.set("stack","overflow",3000) print cache.get("stack") (output: ) None I tried restarting memcache, and here is what's in my settings: CACHES = { 'default'…
Zac Connelly
  • 321
  • 1
  • 2
  • 5
18
votes
1 answer

django querysets + memcached: best practices

Trying to understand what happens during a django low-level cache.set() Particularly, details about what part of the queryset gets stored in memcached. First, am I interpreting the django docs correctly? a queryset (python object) has/maintains its…
jd.
  • 4,543
  • 7
  • 34
  • 40
17
votes
7 answers

Caching queryset choices for ModelChoiceField or ModelMultipleChoiceField in a Django form

When using ModelChoiceField or ModelMultipleChoiceField in a Django form, is there a way to pass in a cached set of choices? Currently, if I specify the choices via the queryset parameter, it results in a database hit. I'd like to cache these…
17
votes
4 answers

How to test django caching?

Is there a way to be sure that a page is coming from cache on a production server and on the development server as well? The solution shouldn't involve caching middleware because not every project uses them. Though the solution itself might be a…
muhuk
  • 15,777
  • 9
  • 59
  • 98
14
votes
3 answers

Django default cache

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:…
rajat
  • 3,415
  • 15
  • 56
  • 90
13
votes
1 answer

How to disable Django REST Framework caching?

I'm just start working with django and DRF, and occure a problem, that is looks like DRF cache responses. I mean - I can change object, create new, or delete it - and DRF keep response, thats nothing is changed. For example, I create an object, but…
GeraldIstar
  • 368
  • 1
  • 4
  • 16
13
votes
2 answers

Contents of locmem cache in Django?

I was trying to use the locmem cache for my web application but couldn't find any documentation on how to see the contents of the cache. I mean I want to check if my keys are being set correctly in the cache. How can I list all the keys in this…
Mayank
  • 357
  • 3
  • 17
1
2 3
16 17