Revert "Bulk-reads and Request caching in Course Grade Report"

This reverts commit 16e9636513.
This commit is contained in:
Sanford Student
2017-05-09 16:25:46 -04:00
parent 524e2f3e24
commit 5388d5d1fc
22 changed files with 130 additions and 477 deletions

View File

@@ -39,14 +39,11 @@ class RequestCache(object):
return crum.get_current_request()
@classmethod
def clear_request_cache(cls, name=None):
def clear_request_cache(cls):
"""
Empty the request cache.
"""
if name is None:
REQUEST_CACHE.data = {}
elif REQUEST_CACHE.data.get(name):
REQUEST_CACHE.data[name] = {}
REQUEST_CACHE.data = {}
def process_request(self, request):
self.clear_request_cache()
@@ -85,43 +82,25 @@ def request_cached(f):
cache the value it returns, and return that cached value for subsequent calls with the
same args/kwargs within a single request
"""
return ns_request_cached()(f)
def ns_request_cached(namespace=None):
"""
Same as request_cached above, except an optional namespace can be passed in to compartmentalize the cache.
Arguments:
namespace (string): An optional namespace to use for the cache. Useful if the caller wants to manage
their own sub-cache by, for example, calling RequestCache.clear_request_cache for their own namespace.
"""
def outer_wrapper(f):
def wrapper(*args, **kwargs):
"""
Outer wrapper that decorates the given function
Arguments:
f (func): the function to wrap
Wrapper function to decorate with.
"""
def inner_wrapper(*args, **kwargs):
"""
Wrapper function to decorate with.
"""
# Check to see if we have a result in cache. If not, invoke our wrapped
# function. Cache and return the result to the caller.
rcache = RequestCache.get_request_cache(namespace)
rcache = rcache.data if namespace is None else rcache
cache_key = func_call_cache_key(f, *args, **kwargs)
# Check to see if we have a result in cache. If not, invoke our wrapped
# function. Cache and return the result to the caller.
rcache = RequestCache.get_request_cache()
cache_key = func_call_cache_key(f, *args, **kwargs)
if cache_key in rcache:
return rcache.get(cache_key)
else:
result = f(*args, **kwargs)
rcache[cache_key] = result
return result
if cache_key in rcache.data:
return rcache.data.get(cache_key)
else:
result = f(*args, **kwargs)
rcache.data[cache_key] = result
return inner_wrapper
return outer_wrapper
return result
wrapper.request_cached_contained_func = f
return wrapper
def func_call_cache_key(func, *args, **kwargs):