# Path: anubis/aggregators.py
# class CachedQuerySetAggregator(QuerySetAggregator):
#     def __init__(self, cache, base_queryset, allowed_filters):
#         super().__init__(base_queryset, allowed_filters)
# 
#         self.cache = cache
# 
#     def make_cache_key(self, expr):
#         model_name = self.base_queryset.model._meta.model_name
#         keys = [model_name, expr["field"]] + expr["args"]
#         keys = [k.replace(":", r"\:") for k in keys]
# 
#         return ":".join(keys)
# 
#     def handle_base_expression(self, base_expression):
#         unit_key = self.make_cache_key(base_expression)
# 
#         cached_value = self.cache.get(unit_key, None)
# 
#         if cached_value is None:
#             queryset = super().handle_base_expression(base_expression)
#             self.cache.set(unit_key, queryset.values_list("id", flat=True))
#         else:
#             queryset = self.base_queryset.filter(id__in=cached_value)
# 
#         return queryset


from django.core.cache import caches
from anubis.aggregators import CachedQuerySetAggregator
        if not self.is_cacheable:
            return super().get_full_state()

        key = "api:" + self.cache_key if self.is_api else self.cache_key

        cache = caches[self.cache]

        cached_value = cache.get(key, None)

        if cached_value is None:
            state = super().get_full_state()

            cache.set(key, dict(state))
        else:
            state = dict(cached_value)

        return state

class CachedUnitMixin:
    """Caches individual units.
    """

    unit_cache = None

    def get_queryset_filter(self, queryset):
        if self.unit_cache is None:
            return super().get_queryset_filter(queryset)

        cache = caches[self.unit_cache]


# Path: anubis/aggregators.py
# class CachedQuerySetAggregator(QuerySetAggregator):
#     def __init__(self, cache, base_queryset, allowed_filters):
#         super().__init__(base_queryset, allowed_filters)
# 
#         self.cache = cache
# 
#     def make_cache_key(self, expr):
#         model_name = self.base_queryset.model._meta.model_name
#         keys = [model_name, expr["field"]] + expr["args"]
#         keys = [k.replace(":", r"\:") for k in keys]
# 
#         return ":".join(keys)
# 
#     def handle_base_expression(self, base_expression):
#         unit_key = self.make_cache_key(base_expression)
# 
#         cached_value = self.cache.get(unit_key, None)
# 
#         if cached_value is None:
#             queryset = super().handle_base_expression(base_expression)
#             self.cache.set(unit_key, queryset.values_list("id", flat=True))
#         else:
#             queryset = self.base_queryset.filter(id__in=cached_value)
# 
#         return queryset


# Path: anubis/views/caching.py
from django.core.cache import caches
from anubis.aggregators import CachedQuerySetAggregator

        if not self.is_cacheable:
            return super().get_full_state()

        key = "api:" + self.cache_key if self.is_api else self.cache_key

        cache = caches[self.cache]

        cached_value = cache.get(key, None)

        if cached_value is None:
            state = super().get_full_state()

            cache.set(key, dict(state))
        else:
            state = dict(cached_value)

        return state

class CachedUnitMixin:
    """Caches individual units.
    """

    unit_cache = None

    def get_queryset_filter(self, queryset):
        if self.unit_cache is None:
            return super().get_queryset_filter(queryset)

        cache = caches[self.unit_cache]


        aggregator = CachedQuerySetAggregator(cache, queryset,