Commits

Jason Moiron  committed 45afb5a

adding filebased caching as per #34

  • Participants
  • Parent commits a5c3000

Comments (0)

Files changed (2)

File johnny/backends/filebased.py

+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+"""Infinite file-based caching.  Caches forever when passed timeout of 0.
+
+To use, change your ``CACHE_BACKEND`` setting to something like this::
+
+    CACHE_BACKEND="johnny.backends.filebased:///var/tmp/my_cache_directory"
+"""
+
+from django.core.cache.backends import filebased
+from django.utils.encoding import smart_str
+import sys
+
+# NOTE: We aren't using smart_str here, because the underlying library will
+# perform a call to md5 that chokes on that type of input;  we'll just not
+# fret the encoding, and things will work alright even with unicode table names
+class CacheClass(filebased.CacheClass):
+    def add(self, key, value, timeout=None):
+        if timeout is 0:
+            timeout = sys.maxint
+        return super(CacheClass, self).add(key, value, timeout)
+
+    def set(self, key, value, timeout=None):
+        if timeout is 0:
+            timeout = sys.maxint
+        return super(CacheClass, self).set(key, value, timeout)
+
+
 # trailing slash.
 # Examples: "http://foo.com/media/", "/media/".
 ADMIN_MEDIA_PREFIX = '/media/'
+#CACHE_BACKEND="johnny.backends.filebased:///tmp/johnny_cache.cc"
 CACHE_BACKEND="johnny.backends.locmem://"
 
+
 # Make this unique, and don't share it with anybody.
 SECRET_KEY = '_vpn1a^j(6&+3qip2me4f#&8#m#*#icc!%=x=)rha4k=!4m8s4'