Remove api page chache -> it is not needed anymore
This commit is contained in:
parent
45533e0b2d
commit
1f7b9252ab
|
|
@ -532,11 +532,6 @@ if "django_redis.cache.RedisCache" in env("IT_DJANGO_CACHE_BACKEND", default="")
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
CACHES["api_page_cache"] = {
|
|
||||||
"BACKEND": "django.core.cache.backends.db.DatabaseCache",
|
|
||||||
"LOCATION": "django_cache_table_api_page",
|
|
||||||
}
|
|
||||||
|
|
||||||
# OAuth/OpenId Connect
|
# OAuth/OpenId Connect
|
||||||
IT_OAUTH_TENANT_ID = env.str("IT_OAUTH_TENANT_ID", default=None)
|
IT_OAUTH_TENANT_ID = env.str("IT_OAUTH_TENANT_ID", default=None)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import logging
|
||||||
|
|
||||||
import structlog
|
import structlog
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.cache import caches
|
|
||||||
from rest_framework.throttling import UserRateThrottle
|
from rest_framework.throttling import UserRateThrottle
|
||||||
from structlog.types import EventDict
|
from structlog.types import EventDict
|
||||||
|
|
||||||
|
|
@ -51,16 +50,3 @@ def first_true(iterable, default=False, pred=None):
|
||||||
# first_true([a,b,c], x) --> a or b or c or x
|
# first_true([a,b,c], x) --> a or b or c or x
|
||||||
# first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
|
# first_true([a,b], x, f) --> a if f(a) else b if f(b) else x
|
||||||
return next(filter(pred, iterable), default)
|
return next(filter(pred, iterable), default)
|
||||||
|
|
||||||
|
|
||||||
def get_api_page_cache():
|
|
||||||
return caches["api_page_cache"]
|
|
||||||
|
|
||||||
|
|
||||||
def api_page_cache_get_or_set(key, func, timeout=60 * 60 * 8):
|
|
||||||
cache = get_api_page_cache()
|
|
||||||
value = cache.get(key)
|
|
||||||
if value is None:
|
|
||||||
value = func()
|
|
||||||
cache.set(key, value, timeout=timeout)
|
|
||||||
return value
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +0,0 @@
|
||||||
from django.core.cache import caches
|
|
||||||
from django.core.management.base import BaseCommand
|
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
|
||||||
def handle(self, *args, **options):
|
|
||||||
self.stdout.write("Clearing course cache")
|
|
||||||
caches["api_page_cache"].clear()
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
import structlog
|
|
||||||
from django.core.cache import caches
|
|
||||||
from django.db.models.signals import post_delete, post_save
|
|
||||||
from wagtail.models import Page
|
|
||||||
|
|
||||||
logger = structlog.get_logger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def get_all_subclasses(cls):
|
|
||||||
all_subclasses = []
|
|
||||||
|
|
||||||
for subclass in cls.__subclasses__():
|
|
||||||
all_subclasses.append(subclass)
|
|
||||||
all_subclasses.extend(get_all_subclasses(subclass))
|
|
||||||
|
|
||||||
return all_subclasses
|
|
||||||
|
|
||||||
|
|
||||||
def invalidate_api_page_cache(sender, **kwargs):
|
|
||||||
logger.debug("invalidate api_page_cache", label="api_page_cache")
|
|
||||||
caches["api_page_cache"].clear()
|
|
||||||
|
|
||||||
|
|
||||||
for subclass in get_all_subclasses(Page):
|
|
||||||
post_save.connect(invalidate_api_page_cache, subclass)
|
|
||||||
post_delete.connect(invalidate_api_page_cache, subclass)
|
|
||||||
|
|
@ -5,7 +5,6 @@ from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from wagtail.models import Page
|
from wagtail.models import Page
|
||||||
|
|
||||||
from vbv_lernwelt.core.utils import api_page_cache_get_or_set
|
|
||||||
from vbv_lernwelt.course.models import (
|
from vbv_lernwelt.course.models import (
|
||||||
CircleDocument,
|
CircleDocument,
|
||||||
CourseCompletion,
|
CourseCompletion,
|
||||||
|
|
@ -39,15 +38,7 @@ def course_page_api_view(request, slug):
|
||||||
if not has_course_access_by_page_request(request, page):
|
if not has_course_access_by_page_request(request, page):
|
||||||
raise PermissionDenied()
|
raise PermissionDenied()
|
||||||
|
|
||||||
with_cache = False
|
data = page.specific.get_serializer_class()(page.specific).data
|
||||||
|
|
||||||
if with_cache:
|
|
||||||
data = api_page_cache_get_or_set(
|
|
||||||
key=request.get_full_path(),
|
|
||||||
func=lambda: page.specific.get_serializer_class()(page.specific).data,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
data = page.specific.get_serializer_class()(page.specific).data
|
|
||||||
|
|
||||||
return Response(data)
|
return Response(data)
|
||||||
except PermissionDenied as e:
|
except PermissionDenied as e:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue