Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions main/management/commands/clear_cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""Command to clear the cache"""

from django.core.management.base import BaseCommand

from main.utils import clear_search_cache


class Command(BaseCommand):
"""Command to clear the cache"""

help = "Command to clear the cache"

def handle(self, *args, **options): # noqa: ARG002
cache_items = clear_search_cache()
self.stdout.write(f"cleared {cache_items} items from cache")
6 changes: 4 additions & 2 deletions main/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,10 @@ def clean_data(data: str) -> str:

def clear_search_cache():
cache = caches["redis"]
cleared = 0
if hasattr(cache, "keys"):
search_keys = cache.keys("views.decorators.cache.cache_page.search.*")
cache.delete_many(search_keys)
cleared += cache.delete_many(search_keys) or 0
search_keys = cache.keys("views.decorators.cache.cache_header.search.*")
cache.delete_many(search_keys)
cleared += cache.delete_many(search_keys) or 0
return cleared
3 changes: 3 additions & 0 deletions scripts/heroku-release-phase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ python $MANAGE_FILE prune_subscription_queries 2>&1 | indent

echo "-----> Generating cache tables"
python $MANAGE_FILE createcachetable 2>&1 | indent

# clear cache entries
python $MANAGE_FILE clear_cache --noinput 2>&1 | indent
Loading