1 # -*- coding: utf-8 -*-
2 from django import template
3 from django.core.cache import cache
4 from ..models import Chunk, Attachment
7 register = template.Library()
11 def chunk(key, cache_time=0):
13 cache_key = 'chunk_' + key
14 c = cache.get(cache_key)
16 c = Chunk.objects.get(key=key)
17 cache.set(cache_key, c, int(cache_time))
19 except Chunk.DoesNotExist:
27 def attachment(key, cache_time=0):
29 cache_key = 'attachment_' + key
30 c = cache.get(cache_key)
32 c = Attachment.objects.get(key=key)
33 cache.set(cache_key, c, int(cache_time))
34 return c.attachment.url
35 except Attachment.DoesNotExist: