-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add management command to clear cache
- Loading branch information
Xavier Medrano
authored and
Xavier Medrano
committed
Apr 18, 2024
1 parent
92a4661
commit 3f51f9e
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Adapted from https://github.com/rdegges/django-clear-cache | ||
from django.conf import settings | ||
from django.core.cache import cache | ||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
|
||
class Command(BaseCommand): | ||
"""A simple management command which clears the site-wide cache.""" | ||
|
||
help = "Fully clear your site-wide cache." | ||
|
||
def handle(self, *args, **kwargs): | ||
try: | ||
assert settings.CACHES | ||
except AttributeError: | ||
raise CommandError("No cache configured. Check CACHES in settings.py.") | ||
|
||
cache.clear() | ||
self.stdout.write("Successfully cleared the cache.") |