Skip to content

Commit

Permalink
Merge branch 'main' into release/2
Browse files Browse the repository at this point in the history
  • Loading branch information
vsalvino committed Aug 21, 2024
2 parents 4b22b13 + 28b7dd6 commit 9b9b23e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
7 changes: 7 additions & 0 deletions docs/releases.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Release Notes
=============


2.5.1
=====

* Bug fix: Support Django 5.1


2.5.0
=====

Expand Down
2 changes: 1 addition & 1 deletion wagtailcache/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
release = ["2", "5", "0"]
release = ["2", "5", "1"]
__version__ = "{0}.{1}.{2}".format(release[0], release[1], release[2])
__shortversion__ = "{0}.{1}".format(release[0], release[1])
16 changes: 8 additions & 8 deletions wagtailcache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ class FetchFromCacheMiddleware(MiddlewareMixin):
Mostly stolen from ``django.middleware.cache.FetchFromCacheMiddleware``.
"""

def __init__(self, get_response=None):
def __init__(self, get_response):
self._wagcache = caches[wagtailcache_settings.WAGTAIL_CACHE_BACKEND]
self.get_response = get_response
self._async_check()
super().__init__(get_response)

def process_request(self, request: WSGIRequest) -> Optional[HttpResponse]:
if not wagtailcache_settings.WAGTAIL_CACHE:
Expand Down Expand Up @@ -250,10 +249,9 @@ class UpdateCacheMiddleware(MiddlewareMixin):
Mostly stolen from ``django.middleware.cache.UpdateCacheMiddleware``.
"""

def __init__(self, get_response=None):
def __init__(self, get_response):
self._wagcache = caches[wagtailcache_settings.WAGTAIL_CACHE_BACKEND]
self.get_response = get_response
self._async_check()
super().__init__(get_response)

def process_response(
self, request: WSGIRequest, response: HttpResponse
Expand Down Expand Up @@ -411,13 +409,15 @@ def _wrapped_view_func(
request: WSGIRequest, *args, **kwargs
) -> HttpResponse:
# Try to fetch an already cached page from wagtail-cache.
response = FetchFromCacheMiddleware().process_request(request)
response = FetchFromCacheMiddleware(view_func).process_request(request)
if response:
return response
# Since we don't have a response at this point, process the request.
response = view_func(request, *args, **kwargs)
# Cache the response.
response = UpdateCacheMiddleware().process_response(request, response)
response = UpdateCacheMiddleware(view_func).process_response(
request, response
)
return response

return _wrapped_view_func
Expand Down

0 comments on commit 9b9b23e

Please sign in to comment.