django-caching

How use Django Cache in view without cache all page

你。 提交于 2020-06-26 14:43:47
问题 I trying to use Django Cache to make better my views. Works great, 400ms to 8ms is perfect. But when user access page for the first time, Django cache page with user info in header and when I try log out, page continue with user info. I try use cache in template too, but isn't good, my problem come from view, so continue 400ms. My settings.py CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', 'LOCATION': 'unique-snowflake', } } My view.py @cache_page(60 * 15)

Changes in DB data not reflecting in the Django queryset in a continuously looping script

你离开我真会死。 提交于 2019-12-22 12:56:11
问题 I am using Django's ORM to get newly added entries from a Db and pass them to a Messaging queue. I am doing this in an infinite while loop , The PROBLEM in every loop iteration I am getting the same queryset even when I have added/deleted/edited entries when this script is running, The code goes like this : while True : sleep(10 seconds) # Below is the problem line, I get the same query-set every time in new_objects # even when I have added/deleted/edited entries while this daemon is running.

How to invalidate cache_page in Django?

纵饮孤独 提交于 2019-12-07 02:18:25
问题 Here is the problem: I have blog app and I cache the post output view for 5 minutes. @cache_page(60 * 5) def article(request, slug): ... However, I'd like to invalidate the cache whenever a new comment is added to the post. I'm wondering how best to do so? I've seen this related question, but it is outdated. 回答1: I would cache in a bit different way: def article(request, slug): cached_article = cache.get('article_%s' % slug) if not cached_article: cached_article = Article.objects.get(slug

Changes in DB data not reflecting in the Django queryset in a continuously looping script

百般思念 提交于 2019-12-06 04:48:23
I am using Django's ORM to get newly added entries from a Db and pass them to a Messaging queue. I am doing this in an infinite while loop , The PROBLEM in every loop iteration I am getting the same queryset even when I have added/deleted/edited entries when this script is running, The code goes like this : while True : sleep(10 seconds) # Below is the problem line, I get the same query-set every time in new_objects # even when I have added/deleted/edited entries while this daemon is running. new_objects = Model.objects.filter(some condition) # Process new_objects and send them to MQ . . and