caching

Disable static file caching in Tornado

Disable static file caching in Tornado Question: By default, Tornado puts a Cache-Control: public header on any file served by a StaticFileHandler. How can this be changed to Cache-Control: no-cache? Asked By: Jordan || Source Answers: Looking into the tornado/web.py it seems that the easiest way is to subclass the StaticFileHandler and override the set_extra_headers …

Total answers: 2

Django Caching for Authenticated Users Only

Django Caching for Authenticated Users Only Question: Question In Django, how can create a single cached version of a page (same for all users) that’s only visible to authenticated users? Setup The pages I wish to cache are only available to authenticated users (they use @login_required on the view). These pages are the same for …

Total answers: 5

How can I memoize a class instantiation in Python?

How can I memoize a class instantiation in Python? Question: Ok, here is the real world scenario: I’m writing an application, and I have a class that represents a certain type of files (in my case this is photographs but that detail is irrelevant to the problem). Each instance of the Photograph class should be …

Total answers: 4

Get list of Cache Keys in Django

Get list of Cache Keys in Django Question: 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’) but still cant figure out …

Total answers: 11

Global variable/Variable caching in Django

Global variable/Variable caching in Django Question: In my website, I want to present to the user the most viewed product categories in a sidebar, in multiple pages. so in each different view I have: variables = RequestContext(request, { (…) ‘most_viewed_cats’: calculate_most_viewed_categories() } and in the various templates {% include "list_most_viewed_categories" %} and in that one: …

Total answers: 1

What is StringIO in python used for in reality?

What is StringIO in python used for in reality? Question: What exactly is StringIO used for? I have been looking around the internet for some examples. However, almost all of the examples are very abstract. And they just show "how" to use it. But none of them show "why" and "in which circumstances" one should/will …

Total answers: 8

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

How to clear the whole cache when using django's page_cache decorator Question: 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 …

Total answers: 3

Is there any nosql flat file database just as sqlite?

Is there any nosql flat file database just as sqlite? Question: Short Question: Is there any nosql flat-file database available as sqlite? Explanation: Flat file database can be opened in different processes to read, and keep one process to write. I think its perfect for read cache if there’s no strict consistent needed. Say 1-2 …

Total answers: 3

How to limit the size of a dictionary?

How to limit the size of a dictionary? Question: I’d like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. …

Total answers: 7

Expire a view-cache in Django?

Expire a view-cache in Django? Question: The @cache_page decorator is awesome. But for my blog I would like to keep a page in cache until someone comments on a post. This sounds like a great idea as people rarely comment so keeping the pages in memcached while nobody comments would be great. I’m thinking that …

Total answers: 15