Add management command to purge caches

This commit is contained in:
Jake Howard 2022-10-02 20:47:40 +01:00
parent 8f66feeaa5
commit 04aa301c75
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 22 additions and 0 deletions

View file

@ -0,0 +1,21 @@
from argparse import ArgumentParser
from django.core.cache import DEFAULT_CACHE_ALIAS, caches
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def add_arguments(self, parser: ArgumentParser) -> None:
parser.add_argument(
"cache",
type=str,
default=DEFAULT_CACHE_ALIAS,
nargs="?",
choices=list(caches),
help="Cache alias. Default: %(default)s",
)
def handle(self, *args: list, **options: dict) -> None:
cache_alias = options["cache"]
self.stdout.write(f"Purging cache {cache_alias}")
caches[cache_alias].clear()

View file

@ -44,6 +44,7 @@ INSTALLED_APPS = [
"website.contrib.mermaid_block", "website.contrib.mermaid_block",
"website.contrib.unsplash", "website.contrib.unsplash",
"website.contrib.singleton_page", "website.contrib.singleton_page",
"website.contrib.wagtail_cache_purge",
"wagtail.contrib.forms", "wagtail.contrib.forms",
"wagtail.contrib.redirects", "wagtail.contrib.redirects",
"wagtail.contrib.modeladmin", "wagtail.contrib.modeladmin",