Ensure comprehensive and consistent cache invalidation patterns across all models that affect cached data. Every model that can impact cached content must have proper invalidation signals, and cache keys should be designed to enable targeted busting without affecting unrelated data.
Key requirements:
post_save
and post_delete
receivers for all models that affect cached data, even if soft deletes are primarily usedteam_id:git_sha:model_name
to enable selective invalidation without clearing unrelated cache entriesExample implementation:
# Bad - easy to forget invalidation for new models
class ExternalDataSource(models.Model):
objects: CacheManager = CacheManager()
# Missing: no invalidation signals
# Good - systematic invalidation pattern
class ExternalDataSource(models.Model):
objects: CacheManager = CacheManager()
@receiver(post_save, sender=ExternalDataSource)
@receiver(post_delete, sender=ExternalDataSource) # Even with soft deletes
def invalidate_external_data_source_cache(sender, instance, **kwargs):
ExternalDataSource.objects.invalidate_cache(instance.team_id)
This prevents the common issue where “ORM writes (including bulk updates, signals, admin edits, scripts) can bypass your invalidation path → stale cache” and ensures that cache invalidation is not an afterthought that developers can easily miss when adding new cached models.
Enter the URL of a public GitHub repository