Created
December 4, 2020 00:21
-
-
Save tubaman/eee2e1ca0bbea684c08a5e7a6a75c191 to your computer and use it in GitHub Desktop.
Timed Cached Template Loader for Django
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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