Hi, I'm building a high traffic intensive application that involves the browser making an AJAX request to the server every second and is expecting the server to return JSON. At any given second the server responds with the same JSON back to each browser (regardless of which user logged in). Because the response is the same for each browser request I decided to remove the DB overhead by caching that response using Redis.
The view responsible for returning the JSON has code similar to this: products_json = [] if cache.get(CACHE_LATEST_PRODUCTS_KEY) == None: //Query the DB as necessary and construct the JSON response ... //Populate the cache cache.set(CACHE_LATEST_PRODUCTS_KEY, products_json) else: products_json = cache.get(CACHE_LATEST_PRODUCTS_KEY) In settings.py TIMEOUT is set to 1. I have 2 questions: 1) In a clustered environment where there are several django servers running, each of those servers initially will end up querying the DB to construct the JSON, this can also happen at any time in the future if the entry expires in the cache while multiple requests are being processed by the django servers. How can I synchronize the cache look ups so that only one of the Redis SET's takes place. Should I take out the code that queries the db and sets the cache entry from the view and move that logic to some sort of periodic task? 2) Is it possible to cache for less than a second? I've tried setting TIMEOUT to 0.7 but I didn't see the results I was expecting.. Many Thanks, Moe -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.