Django Redis
from django.core.cache import cache
# Cache an object for 1 hour
cache.set("my_object", my_object, timeout=3600)
# Retrieve the cached object
my_object = cache.get("my_object")from django.core.cache import cache
from django.db.models import QuerySet
# Cache a queryset for 1 hour
cache.set("my_queryset", my_queryset, timeout=3600)
# Retrieve the cached queryset
my_queryset = cache.get("my_queryset")from django.core.cache import cache
from django.template import Template, Context
# Cache a template fragment for 1 hour
cache.set("my_fragment", Template("{{ my_variable }}").render(Context({"my_variable": "value"})), timeout=3600)
# Retrieve the cached template fragment
my_fragment = cache.get("my_fragment")