diff --git a/kolibri/core/utils/cache.py b/kolibri/core/utils/cache.py index 99245a6f302..e0c9b8bd2f3 100644 --- a/kolibri/core/utils/cache.py +++ b/kolibri/core/utils/cache.py @@ -3,6 +3,7 @@ from django.core.cache import caches from django.core.cache import InvalidCacheBackendError from django.utils.functional import SimpleLazyObject +from redis_cache import RedisCache as BaseRedisCache logger = logging.getLogger(__name__) @@ -61,3 +62,15 @@ def save(self): logger.info("Overwriting Redis config") self.client.config_rewrite() self.changed = False + + +class RedisCache(BaseRedisCache): + def set(self, *args, **kwargs): + """ + Overwrite the set method to not return a value, in line with the Django cache interface + This causes particular issues for Django's caching middleware, which expects the set method to return None + as it invokes it directly in a lambda in the response.add_post_render_callback method + We use a similar pattern in our own caching decorator in kolibri/core/content/api.py and saw errors + due to the fact if the lambda returns a value, it is interpreted as a replacement for the response object. + """ + super(RedisCache, self).set(*args, **kwargs) diff --git a/kolibri/deployment/default/cache.py b/kolibri/deployment/default/cache.py index dc8884db219..85d3b35c1c4 100644 --- a/kolibri/deployment/default/cache.py +++ b/kolibri/deployment/default/cache.py @@ -38,7 +38,7 @@ if cache_options["CACHE_BACKEND"] == "redis": base_cache = { - "BACKEND": "redis_cache.RedisCache", + "BACKEND": "kolibri.core.utils.cache.RedisCache", "LOCATION": cache_options["CACHE_LOCATION"], # Default time out of each cache key "TIMEOUT": cache_options["CACHE_TIMEOUT"],