Skip to content
django-redis-caching logo

Django Redis Caching Skill

django-redis-caching

Django Redis caching with django-cacheops. This skill should be used when implementing caching, adding cache invalidation, optimizing API performance, modifying models that affect cached data, or debugging cache-related issues in the Django backend.

SKILL.md

Full skill instructions

Django Redis Caching Skill

Implements Redis caching with django-cacheops for the DTX Django backend.

Quick Reference

Cacheops Configuration

All models use 1-hour cache timeout (configured in settings.py):

CACHEOPS = {
    "app.tournament": {"ops": "all", "timeout": 60 * 60},
    "app.team": {"ops": "all", "timeout": 60 * 60},
    "app.customuser": {"ops": "all", "timeout": 60 * 60},
    "app.draft": {"ops": "all", "timeout": 60 * 60},
    "app.game": {"ops": "all", "timeout": 60 * 60},
    "app.draftround": {"ops": "all", "timeout": 60 * 60},
}

View Caching Pattern

from cacheops import cached_as

def list(self, request, *args, **kwargs):
    cache_key = f"model_list:{request.get_full_path()}"

    @cached_as(Model1, Model2, extra=cache_key, timeout=60 * 60)
    def get_data():
        queryset = self.filter_queryset(self.get_queryset())
        serializer = self.get_serializer(queryset, many=True)
        return serializer.data

    return Response(get_data())

Cache Invalidation Pattern

from cacheops import invalidate_obj, invalidate_model

def save(self, *args, **kwargs):
    super().save(*args, **kwargs)
    # Invalidate specific instance
    invalidate_obj(self.related_obj)
    # Invalidate entire model cache
    invalidate_model(RelatedModel)

DTX Model Cache Dependencies

When modifying data, invalidate these related caches:

Changed ModelAlso Invalidate
DraftRoundTournament, Draft, Team
DraftTournament
TeamTournament (if tournament-scoped)
GameTournament, Team
CustomUserTeam (if member changes)

Key Principles

  1. Invalidate on Write: Always invalidate related caches after mutations
  2. Monitor Dependencies: Use @cached_as(Model1, Model2, ...) to auto-invalidate
  3. Use Specific Keys: Include request path or pk in cache keys
  4. Keep Fresh for Detail: Use keep_fresh=True for single-object retrieval

Detailed References

Common Operations

Disable Cache for Management Commands

DISABLE_CACHE=true python manage.py <command>

Manual Cache Invalidation

from cacheops import invalidate_all, invalidate_model, invalidate_obj

# Nuclear option - invalidate everything
invalidate_all()

# Invalidate all instances of a model
invalidate_model(Tournament)

# Invalidate specific instance
invalidate_obj(tournament)

Check if Cache is Working

from django.core.cache import cache
cache.set('test_key', 'test_value', 30)
print(cache.get('test_key'))  # Should print 'test_value'

Timeout Guidelines

Data TypeTimeoutReason
Static data60 * 60 (1h)Rarely changes
Tournament state60 * 10 (10m)Changes during events
Draft rounds60 * 10 (10m)Active during drafts
External API (Discord)15sRate limiting, freshness

More Other skills

Delegate independent tasks to specialized agents working concurrently with isolated context.

295.4K 206.3K
View

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

179.7K 100.1K
View

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

179.7K 89.5K
View

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

179.7K 76.1K
View

Fundamental design principles for writing maintainable, testable Python code.

40.2K 21.9K
View

Modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first strategies.

40.2K 20K
View

Generate Playwright tests from scenarios using interactive browser exploration and validation.

39.7K 18.2K
View

Modern React state management with Redux Toolkit, Zustand, Jotai, and React Query for every state category.

40.2K 14.7K
View

GDPR-compliant data handling with consent management, data subject rights, and privacy controls.

40.2K 14.3K
View

Python error handling patterns including input validation, exception hierarchies, and partial failure handling. Use when implementing validation logic, designing exception strategies, handling batch processing failures, or building robust APIs.

40.2K 13.5K
View

Detailed multi-file refactor planning with safety checks and rollback guidance.

39.7K 13K
View