# 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

# caching.py - caching related views.

# This file is part of Anubis.

# Anubis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Anubis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.



class NoCacheMixin:
    def get(self, *args, **kwargs):
        response = super().get(*args, **kwargs)

        response['Cache-Control'] = "no-cache, no-store, must-revalidate"
        response['Pragma'] = "no-cache"
        response['Expires'] = "0"

        return response


# 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


# caching.py - caching related views.

# This file is part of Anubis.

# Anubis is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# Anubis is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.



class NoCacheMixin:
    def get(self, *args, **kwargs):
        response = super().get(*args, **kwargs)

        response['Cache-Control'] = "no-cache, no-store, must-revalidate"
        response['Pragma'] = "no-cache"
        response['Expires'] = "0"

        return response


class CachedSearchMixin: