Add management command to clear cache
This commit is contained in:
parent
32a1486840
commit
2fe0960623
1 changed files with 20 additions and 0 deletions
20
website/common/management/commands/clear_cache.py
Normal file
20
website/common/management/commands/clear_cache.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
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,
|
||||||
|
choices=sorted(list(caches)),
|
||||||
|
help="Cache to clear",
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle(self, *args: list, **options: dict) -> None:
|
||||||
|
cache_name: str = options["cache"] # type: ignore
|
||||||
|
caches[cache_name].clear()
|
||||||
|
self.stdout.write(f"Cleared cache '{cache_name}'.")
|
Loading…
Reference in a new issue