Skip to content

Commit

Permalink
Fix reversion from rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
aweakley committed Jul 29, 2024
1 parent caec651 commit 1254d88
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
17 changes: 0 additions & 17 deletions testproject/home/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,6 @@ def test_cache_keyring(self):
# Compare Keys
self.assertEqual(keyring_item.url, url)

@override_settings(WAGTAIL_CACHE_BACKEND="one_second")
def test_cache_keyring_no_uri_key_duplication(self):
# First get to populate keyring
self.get_miss(self.page_cachedpage.get_url())
# Wait a short time
time.sleep(0.5)
# Fetch a different page
self.get_miss(self.page_wagtailpage.get_url())
# Wait until the first page is expired, but not the keyring
time.sleep(0.6)
# Fetch the first page again
self.get_miss(self.page_cachedpage.get_url())
# Check the keyring does not contain duplicate uri_keys
url = "http://%s%s" % ("testserver", self.page_cachedpage.get_url())
keyring = self.cache.get("keyring")
self.assertEqual(len(keyring.get(url, [])), 1)

def test_clear_cache(self):
# First get should miss cache.
self.get_miss(self.page_cachedpage.get_url())
Expand Down
19 changes: 10 additions & 9 deletions wagtailcache/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Functionality to set, serve from, and clear the cache.
"""

import datetime
import logging
import re
from enum import Enum
Expand All @@ -24,6 +25,7 @@
from django.utils.cache import learn_cache_key
from django.utils.cache import patch_response_headers
from django.utils.deprecation import MiddlewareMixin
from django.utils.timezone import now
from wagtail import hooks

from wagtailcache.models import KeyringItem
Expand Down Expand Up @@ -340,15 +342,14 @@ def process_response(
# (of the chopped request, not the real one).
cr = _chop_querystring(request)
uri = unquote(cr.build_absolute_uri())
keyring = self._wagcache.get("keyring", {})
# Get current cache keys belonging to this URI.
# This should be a list of keys.
uri_keys: List[str] = keyring.get(uri, [])
# Append the key to this list if not already present and save.
if cache_key not in uri_keys:
uri_keys.append(cache_key)
keyring[uri] = uri_keys
self._wagcache.set("keyring", keyring)

expiry = now() + datetime.timedelta(seconds=timeout)
KeyringItem.objects.set(
expiry=expiry,
key=cache_key,
url=uri,
)

if isinstance(response, SimpleTemplateResponse):

def callback(r):
Expand Down

0 comments on commit 1254d88

Please sign in to comment.