Skip to content

Commit

Permalink
Management command for clearing caches, clear caches upon deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Jan 15, 2025
1 parent 4c53d21 commit 3bc6c66
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions fabfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def deploy(ctx):
build(ctx)
down(ctx)
up(ctx)
clear_caches(ctx)


@task
Expand All @@ -124,6 +125,14 @@ def nginx(ctx):
conn.run('sudo service nginx restart')


@task
def clear_caches(ctx):
if 'network' not in ctx.config.keys(): return
conn = ctx.config.run.env['conn']
with conn.cd(ctx.config.project_dir):
conn.run(f'docker-compose -f compose/{ctx.config.network}.yml --env-file {ctx.config.project_dir}/.env exec -T web python manage.py clear_caches')


@task
def logs(ctx):
if 'network' not in ctx.config.keys(): return
Expand Down
19 changes: 19 additions & 0 deletions main/management/commands/clear_caches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.core.management.base import BaseCommand
from django.conf import settings


class Command(BaseCommand):
help = "Clear balance and transaction history caches"

def handle(self, *args, **options):

# delete balance caches
cache = settings.REDISKV
balance_keys = cache.keys(f'wallet:balance:*')
if balance_keys:
cache.delete(*balance_keys)

# delete wallet history caches
history_cache_keys = cache.keys(f'wallet:history:*')
if history_cache_keys:
cache.delete(*history_cache_keys)

0 comments on commit 3bc6c66

Please sign in to comment.