1 from django import template
2 from django.db import models
3 from django.core.cache import cache
6 register = template.Library()
8 Chunk = models.get_model('chunks', 'chunk')
9 Attachment = models.get_model('chunks', 'attachment')
13 def chunk(key, cache_time=0):
15 cache_key = Chunk.cache_key(key)
16 c = cache.get(cache_key)
18 c = Chunk.objects.get(key=key)
19 cache.set(cache_key, c, int(cache_time))
21 except Chunk.DoesNotExist:
29 def attachment(key, cache_time=0):
31 cache_key = 'attachment_' + key
32 c = cache.get(cache_key)
34 c = Attachment.objects.get(key=key)
35 cache.set(cache_key, c, int(cache_time))
36 return c.attachment.url
37 except Attachment.DoesNotExist: