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
0 answers

Django QuerySet cache not set when using prefetch_related on reverse foreign key objects in query

Not sure if this is a bug in django or I am approaching this from the wrong angle. I need to run a query that brings back all 'site' model objects but also some other model objects that relate via foreign key to the site model objects. To do this I…
chewynougat
  • 1,099
  • 2
  • 11
  • 19
2
votes
1 answer

Django: how to handle caching in views that differ for Ajax requests?

I have a Django application and a postgres backend. It's essentially a search site with a large database, and the data typically changes once a day. I would like to start caching, to reduce load on the database. I've set up memcached, but I have…
Richard
  • 62,943
  • 126
  • 334
  • 542
2
votes
1 answer

Django cache.set() fails on a class with a GenericForeignKey, What can be the cause?

I have a model with a GenericForeignKey. When calling cache.set(key, trac_obj), it fails. I wonder if the GenericForeignKey is the culprit? # models.py class Trac(models.Model): user = models.ForeignKey(User, related_name="%(class)s",…
Val Neekman
  • 17,692
  • 14
  • 63
  • 66
2
votes
1 answer

How does Django cache system works?

How does Django cache system works?
Aventador
  • 205
  • 2
  • 11
2
votes
1 answer

Can not access the static resource

I'm using Mezzanine, django-compressor and amazon-s3. I use django-compressor to compress css file. I have deployed the website to Heroku and stored the static resource successfully. However, after a period, all the css are lost. And below is the…
Thinh Phan
  • 655
  • 1
  • 14
  • 27
1
vote
2 answers

Django CACHE_BACKEND Error

So Im running into this CACHE error when I try to runserver or syncdb. Here is the traceback: https://gist.github.com/1538051 I tried inserting this into the settings.py file: CACHE_BACKEND = { 'default': { 'BACKEND':…
cclerv
  • 2,921
  • 8
  • 35
  • 43
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
0 answers

Does Django open and close connection to cache every time I call cache.delete(key)?

Consider the following code snippet: from django.core.cache import cache cache.delete('key_1') cache.delete('key_2') If i'm using an Instance of Redis as my default cache, will Django create two seperate connections to the Redis instance, for each…
Scratcha
  • 1,359
  • 1
  • 14
  • 22
1
vote
1 answer

While using Cache In DRF after using POST request new data is not being displayed on client side

I have implemented cache for my articles views, and have set cache page. Currently the issue that i am facing is when i try to POST request data to create new article, the page remains the same. What i want to do is be able to POST article while i…
1
vote
1 answer

Asynchronous data fetching and cache handling

I'm planning on deploying a dynamic site that needs certain tasks to be done periodically in the background, let's say every hour or two. The data that i need to output is strictly depending on the result of those queries. Now, the problem is that…
Nelloverflow
  • 1,511
  • 1
  • 11
  • 15
1
vote
1 answer

How to display local-memory cache in Django Templates?

I set the local-memory cache "message" as shown below: from django.core.cache import cache cache.set("message", "success", 300) Then, I tried to display it in the Django Template "index.html" as shown below: # "index.html" {{ cache.get.message…
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
1
vote
0 answers

How to cache object in django template and update if it was changed?

I have a simple Django app with a single view for displaying the product list: from time import sleep class ProductListView(ListView): model = Product paginate_by = 50 allow_empty = True def get(self, *args,…
Daniil
  • 51
  • 3
1
vote
1 answer

Django and redis adding :1 to keys

I'm using django-redis to store some data on my website, and I have a problem where Redis is adding :1 at the beginning so my key looks like this: :1:my_key I'm not sure why is it doing this, I've read the documentation on django-redis and I…
1
vote
1 answer

Django caches user object

Our websites sometimes has around 600 authenticated users trying to register for an event in a timeframe of 5 min. We have a VPS with 1 CPU and 1GB ram. On these moments the site slows down and gives a 502 error. For that reason I'm using per-site…
A. Nurb
  • 496
  • 1
  • 3
  • 17