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>
15 lines
630 B
Python
15 lines
630 B
Python
"""باطلکردنِ کشِ لیستِ پلنها با هر تغییرِ 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)
|