Fixed some bugs in cache_mixins.py

This commit is contained in:
2023-08-28 05:03:49 +03:00
parent fef71feffa
commit d6033baa72

View File

@@ -78,16 +78,16 @@ class CacheSetMixin(CacheUniqueUrl):
def caching_function(response): def caching_function(response):
# Writes the response to the cache # Writes the response to the cache
try: try:
if cls.cache_vary_on_user: if self.cache_vary_on_user:
cls.cache.set(key=f"{cls.cache_prefix}.{request.user}.{self.filters_string}", self.cache.set(key=f"{self.cache_prefix}.{request.user}.{self.filters_string}",
value = response.data, value = response.data,
timeout=60*cls.cache_timeout_mins) timeout=60*self.cache_timeout_mins)
else: else:
cls.cache.set(key=f"{cls.cache_prefix}.{self.filters_string}", self.cache.set(key=f"{self.cache_prefix}.{self.filters_string}",
value = response.data, value = response.data,
timeout=60*cls.cache_timeout_mins) timeout=60*self.cache_timeout_mins)
except: except:
cls.logger.exception(f"Cache set attempt for {cls.__class__.__name__} failed.") self.logger.exception(f"Cache set attempt for {self.__class__.__name__} failed.")
return caching_function return caching_function
# Register the post rendering hook to the response # Register the post rendering hook to the response
@@ -119,4 +119,4 @@ class CacheDeleteMixin(CacheUniqueUrl):
else: else:
self.cache.delete(f"{self.cache_prefix}.{self.filters_string}") self.cache.delete(f"{self.cache_prefix}.{self.filters_string}")
except: except:
self.logger.exception(f"Cache delete attempt for {cls.__class__.__name__} failed.") self.logger.exception(f"Cache delete attempt for {self.__class__.__name__} failed.")