Cache Helper Utilities
A snippet adding wrapper helpers around Django cache API.
# models.py
from django.db import models
class Counter(models.Model):
name = models.CharField(max_length=50, unique=True)
value = models.IntegerField(default=0)
# admin.py
from django.contrib import admin
from .models import Counter
@admin.register(Counter)
class CounterAdmin(admin.ModelAdmin):
list_display = ("name","value")
from django.core.cache import cache
def cache_get(key, default=None): return cache.get(key, default)
def cache_set(key, value, timeout=300): cache.set(key, value, timeout); return value
def cache_del(key): cache.delete(key)
Explanation:
- Wrap Django cache API to standardize timeouts and naming.
- Use per-view or low-level cache depending on the use case.
- Category Utilities & Miscellaneous
- Total Views 427
- Last Modified 16 July, 2026
- Tags #cache #utilities #performance #helpers
Previous snippet
Custom Storage Backend (Local/Cloud)
Next snippet