Skip to content

Commit

Permalink
add management command to clear cache
Browse files Browse the repository at this point in the history
  • 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.
19 changes: 19 additions & 0 deletions lametro/management/commands/clear_cache.py
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.")

0 comments on commit 3f51f9e

Please sign in to comment.