Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Update cache_control fix based on wagtail.org's
Browse files Browse the repository at this point in the history
  • Loading branch information
katdom13 committed Dec 20, 2023
1 parent bf06055 commit 7aea72a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 9 additions & 0 deletions tbx/core/utils/cache.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control

from wagtail.contrib.frontend_cache.utils import purge_url_from_cache
Expand Down Expand Up @@ -29,3 +30,11 @@ def get_default_cache_control_kwargs():
def get_default_cache_control_decorator():
cache_control_kwargs = get_default_cache_control_kwargs()
return cache_control(**cache_control_kwargs)


def get_default_cache_control_method_decorator(original_method):
@method_decorator(get_default_cache_control_decorator())
def decorated_method(self, *args, **kwargs):
return original_method(self, *args, **kwargs)

return decorated_method
10 changes: 5 additions & 5 deletions tbx/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
from django.conf import settings
from django.contrib import admin
from django.urls import include, path
from django.utils.decorators import method_decorator
from django.views.decorators.cache import never_cache
from django.views.decorators.vary import vary_on_headers

from tbx.core import urls as torchbox_urls
from tbx.core.utils.cache import get_default_cache_control_decorator
from tbx.core.utils.cache import (
get_default_cache_control_decorator,
get_default_cache_control_method_decorator,
)
from tbx.core.views import robots
from wagtail import urls as wagtail_urls
from wagtail.admin import urls as wagtailadmin_urls
Expand Down Expand Up @@ -85,9 +87,7 @@
),
)

Page.serve = method_decorator(get_default_cache_control_decorator(), name="serve")(
Page.serve
)
Page.serve = get_default_cache_control_method_decorator(Page.serve)

# Join private and public URLs.
urlpatterns = (
Expand Down

0 comments on commit 7aea72a

Please sign in to comment.