Skip to content

Instantly share code, notes, and snippets.

@tubaman
Created December 4, 2020 00:21
Show Gist options
  • Save tubaman/eee2e1ca0bbea684c08a5e7a6a75c191 to your computer and use it in GitHub Desktop.
Save tubaman/eee2e1ca0bbea684c08a5e7a6a75c191 to your computer and use it in GitHub Desktop.
Timed Cached Template Loader for Django
from django.template.loaders.cached import Loader as CachedLoader
from django.conf import settings
from .cacheddict import CachedDict
class Loader(CachedLoader):
"""A cached template loader where the templates expire after self.timeout
seconds.
Take django.template.loaders.cached.Loader and replace the dicts with our
CachedDict.
"""
def __init__(self, engine, loaders):
super(Loader, self).__init__(engine, loaders)
timeout = settings.TIMED_CACHED_LOADER_TIMEOUT
self.template_cache = CachedDict(timeout=timeout)
self.get_template_cache = CachedDict(timeout=timeout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment