Skip to content

Instantly share code, notes, and snippets.

@valtron
valtron / resources.py
Created July 23, 2012 20:39
Manages invalidation of css/js files to the browser by using the md5 hash, and can track dependencies between files.
import os
import re
from django.conf import settings
from django.utils.safestring import mark_safe
class ResourceType(object):
def __init__(self, folder, extension, html):
self.folder = folder
self.extension = extension
@valtron
valtron / cached_manager.py
Created July 19, 2012 22:49
Caches simple queries on one or more unique fields
from django.db import models
class CachedManager(models.Manager):
"""
Caches accesses in the form
Model.objects.get(field = value)
for each field in cached_fields.
Cache is invalidated on any delete or update operation,
regardless of whether anything was actually deleted or updated.
"""