cache the subscription plans list

subscription/views.py
  - PlansListView: served from cache (subscription:plans:v1, 1h TTL);
    plans change ~never and the list is read on every subscription screen.
subscription/receivers.py (new)
  - post_save/post_delete on Plan -> cache.delete(PLANS_CACHE_KEY).
subscription/apps.py
  - SubscriptionConfig.ready() imports receivers.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-30 08:46:30 +03:30
parent d25ecab0b3
commit 40b4dd53a9
3 changed files with 41 additions and 15 deletions

14
subscription/receivers.py Normal file
View File

@@ -0,0 +1,14 @@
"""باطل‌کردنِ کشِ لیستِ پلن‌ها با هر تغییرِ Plan (از ادمین)."""
from django.core.cache import cache
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from .models import Plan
PLANS_CACHE_KEY = 'subscription:plans:v1' # هم‌تراز با subscription/views.py
@receiver(post_save, sender=Plan, dispatch_uid='subscription_invalidate_plans_cache_on_save')
@receiver(post_delete, sender=Plan, dispatch_uid='subscription_invalidate_plans_cache_on_delete')
def _invalidate_plans_cache(sender, **kwargs):
cache.delete(PLANS_CACHE_KEY)