Ensure locale names are cleared entirely when needed

`lru_cache.cache_clear` only clears the cache in the current thread.
pull/10897/head
Jake Howard 2023-08-30 09:28:40 +01:00 zatwierdzone przez LB (Ben Johnston)
rodzic 598aae78c5
commit 578ae520f3
3 zmienionych plików z 14 dodań i 8 usunięć

Wyświetl plik

@ -312,7 +312,8 @@ class TestComponentTag(SimpleTestCase):
("fr", "French"),
("ro", "Romanian"),
("ru", "Russian"),
]
],
CACHES={"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}},
)
class TestInternationalisationTags(TestCase):
def setUp(self):

Wyświetl plik

@ -11,6 +11,7 @@ from anyascii import anyascii
from django.apps import apps
from django.conf import settings
from django.conf.locale import LANG_INFO
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.core.exceptions import ImproperlyConfigured, SuspiciousOperation
from django.core.signals import setting_changed
@ -334,17 +335,21 @@ def get_supported_content_language_variant(lang_code, strict=False):
raise LookupError(lang_code)
@functools.lru_cache
def get_locales_display_names() -> dict:
"""
Cache of the locale id -> locale display name mapping
"""
from wagtail.models import Locale # inlined to avoid circular imports
locales_map = {
locale.pk: locale.get_display_name() for locale in Locale.objects.all()
}
return locales_map
cached_map = cache.get("wagtail_locales_display_name")
if cached_map is None:
cached_map = {
locale.pk: locale.get_display_name() for locale in Locale.objects.all()
}
cache.set("wagtail_locales_display_name", cached_map)
return cached_map
@receiver(setting_changed)

Wyświetl plik

@ -2,6 +2,7 @@ import logging
from contextlib import contextmanager
from asgiref.local import Local
from django.core.cache import cache
from django.db import transaction
from django.db.models.signals import (
post_delete,
@ -12,7 +13,6 @@ from django.db.models.signals import (
)
from modelcluster.fields import ParentalKey
from wagtail.coreutils import get_locales_display_names
from wagtail.models import Locale, Page, ReferenceIndex, Site
logger = logging.getLogger("wagtail")
@ -39,7 +39,7 @@ def post_delete_page_log_deletion(sender, instance, **kwargs):
def reset_locales_display_names_cache(sender, instance, **kwargs):
get_locales_display_names.cache_clear()
cache.delete("wagtail_locales_display_name")
reference_index_auto_update_disabled = Local()