middleware.py 521 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import threading

_request_cache_threadlocal = threading.local()
_request_cache_threadlocal.data = {}

class RequestCache(object):
    @classmethod
    def get_request_cache(cls):
        return _request_cache_threadlocal
            
    def clear_request_cache(self):
        _request_cache_threadlocal.data = {}

    def process_request(self, request):
        self.clear_request_cache()
        return None

    def process_response(self, request, response):
        self.clear_request_cache()
        return response