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

CSRF error when using a cached response

I am doing some aggressive caching and this results in a CSRF error when I use a previously cached old response. Is there a way to just refresh the csrf token inside the cached response? Unable to understand the Caching section in…
sureshvv
  • 4,234
  • 1
  • 26
  • 32
2
votes
1 answer

How to optionally cache a view in Django

I have created a view in my Django app that requires authentication to load. If the credentials are incorrect, then an error 403 page is sent back. Since I declared the view to be cached in the urls.py file, like this... …
turtlefranklin
  • 509
  • 6
  • 14
2
votes
1 answer

Django Cache: Caching thousands of queries for a long time, on basic server resources

I am building a website having in my mind that hundreds (I wish thousands!) of 'get' queries -per day- will be cached for a couple of months in the filesystem. Reading the cache documentation, however, I observe that the default values lean towards…
raratiru
  • 8,748
  • 4
  • 73
  • 113
2
votes
1 answer

django cache not working as expected

I'd like to add simple cache functionality to my site. I have enabled cache for anonymous users, but it does not work as expected. I'm using memcached. settings.py ########################### caching ################################# CACHE_PORT =…
Lucas03
  • 2,267
  • 2
  • 32
  • 60
2
votes
1 answer

How to get remaining timeout in Django cache

I'm throttling the post requests on a view that lets users add articles. I'm currently using a decorator like so: def throttle_post(func, duration=60): def inner(request, *args, **kwargs): if request.method == 'POST': …
davegri
  • 2,206
  • 2
  • 26
  • 45
2
votes
1 answer

Django REST Framework - how to do Token Authentication with Memcached

I am using TokenAuthentication for several of my DRF views. The view code itself have optimized logic for to use memcached if the key exists in the cache - to speed up by reducing DB queries. However, I see that for each of the API requests from…
2
votes
0 answers

Somehow CELERY_ALWAYS_EAGER = True not works in settings of Django

I've set CELERY_ALWAYS_EAGER = True in the settings of django at test env. But somehow I still got this message. ERROR:cacheback:Unable to trigger task asynchronously - failing over to synchronous refresh ERROR:cacheback:[Errno 111] Connection…
Han Jubel
  • 153
  • 1
  • 1
  • 5
2
votes
1 answer

Django issue (cache?!)

I am having an odd issue. This is my view: def get_date_range(this_week=True, last_week=False, older_than_two_weeks=False): dates = {} d = datetime.today().strftime('%Y-%m-%d') dt = datetime.strptime(d, '%Y-%m-%d') if this_week: …
Dave
  • 43
  • 5
2
votes
1 answer

Possible interaction issue between Django 1.7.4 and django-cacheops 2.2.1

I am upgrading a django app from 1.6 to 1.7. The app uses django-cacheops to store the results of a query. After the switch to Django 1.7 the following error is raised on all requests but the first one: Traceback (most recent call last): File…
Douglas Anderson
  • 674
  • 7
  • 19
2
votes
1 answer

What are best practices for caching for a "Home Feed" or a "News Feed" in Django

I use Django as an API for my mobile front end. I just send JSON back and forth. I've created an endpoint for a home feed. Each user has a unique home feed depending on the people that they follow. Users post a photo, and that photo is pushed out to…
deadlock
  • 7,048
  • 14
  • 67
  • 115
2
votes
2 answers

How can I schedule the invalidation of a redis cache?

I am using django as a framework to build a content management system for a site with a blog. Each blog post will have a route that contains a unique identifier for the blog post. These blog posts can be scheduled and have an expiry date. This means…
2
votes
1 answer

What steps are needed to implement memcached in a Django application?

I have my existing Django web application that uses a MySQLDB without memcaching. I would like to implement memcaching to improve the responsiveness of this site. I see the instructions here. However, these instructions leave me with some…
Saqib Ali
  • 11,931
  • 41
  • 133
  • 272
2
votes
0 answers

In Django, how can I set db connection timeout?

OK, I know it's not that simple. I have two db connections defined in my settings.py: default and cache. I'm using DatabaseCache backend from django.core.cache. I have database router defined so I can use separate database/schema/table for my models…
mnowotka
  • 16,430
  • 18
  • 88
  • 134
2
votes
5 answers

How to get expiration time from cache in Django?

With django.core.cache.backends.locmem.LocMemCache this worked: key = cache.make_key('foo') cache.validate_key(key) t = cache._expire_info.get(key) But it breaks with django.core.cache.backends.memcached.MemcachedCache I get error:…
petr0
  • 411
  • 7
  • 10
2
votes
1 answer

Django KEY_PREFIX vs CACHE_MIDDLEWARE_KEY_PREFIX

Until now I have been I have been using a single memcached instance for my 4 sites. On three of them I use a KEY_PREFIX because the documentation implied that I need to do that. Everything has been fine but now I need to periodically purge the…
rh0dium
  • 6,811
  • 4
  • 46
  • 79