use a request-scoped cache to keep the metadata inheritence tree around for the whole request. This means we should only do one trip to Memcached/Mongo per course per request. This is expected to keep memory utilization down
This commit is contained in:
0
common/djangoapps/request_cache/__init__.py
Normal file
0
common/djangoapps/request_cache/__init__.py
Normal file
20
common/djangoapps/request_cache/middleware.py
Normal file
20
common/djangoapps/request_cache/middleware.py
Normal file
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user