These are chat archives for django/django
In the online server I am having an issue
Error during WebSocket handshake: Unexpected response code: 500
restartedthe server... And it works now. Zzz :laughing:
Have you tried turning it on and off again?
i am writing a Django caching middleware, that takes a list of URLs from the settings file and caches them.
CACHE_URLS = [('^index$', 60*60), ]
this middleware checks the request URL and caches the page for the duration specified in settings. If the page was found in the cache, return the cached result and don’t process the page.
from django.http import HttpResponse from pawame.settings import CACHE_URLS from django.core.cache import cache class CacheUrls(object): def __init__(self, get_response): self.get_response = get_response # One-time configuration and initialization. def __call__(self, request): response = self.get_response(request) request_url = request.path.strip('/') for to_cache_url in CACHE_URLS: if request_url in to_cache_url: if cache.get(request_url): # use the response body return HttpResponse(cache.get(request_url)) else: # cache here body = response url = request_url time_to_cache = to_cache_url cache.set(url, body, time_to_cache) return response
This is working, but is there a better way of achieveing what i described above?
PS I am using Redis as my cache backend.