Changeset 8215 for django/branches/gis/django/core/cache
- Timestamp:
- 08/05/08 12:15:33 (5 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/core/cache/backends/base.py (modified) (1 diff)
- django/branches/gis/django/core/cache/backends/filebased.py (modified) (8 diffs)
- django/branches/gis/django/core/cache/backends/locmem.py (modified) (1 diff)
- django/branches/gis/django/core/cache/__init__.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/django/core/cache/backends/base.py
r6815 r8215 64 64 return self.get(key) is not None 65 65 66 __contains__ = has_key 66 def __contains__(self, key): 67 """ 68 Returns True if the key is in the cache and has not expired. 69 """ 70 # This is a separate method, rather than just a copy of has_key(), 71 # so that it always has the same functionality as has_key(), even 72 # if a subclass overrides it. 73 return self.has_key(key) django/branches/gis/django/core/cache/backends/filebased.py
r6920 r8215 1 1 "File-based cache backend" 2 2 3 import md54 import os,time3 import os 4 import time 5 5 try: 6 6 import cPickle as pickle 7 7 except ImportError: 8 8 import pickle 9 9 10 from django.core.cache.backends.base import BaseCache 11 from django.utils.hashcompat import md5_constructor 10 12 11 13 class CacheClass(BaseCache): 12 14 def __init__(self, dir, params): 13 15 BaseCache.__init__(self, params) 14 16 15 17 max_entries = params.get('max_entries', 300) 16 18 try: … … 18 20 except (ValueError, TypeError): 19 21 self._max_entries = 300 20 22 21 23 cull_frequency = params.get('cull_frequency', 3) 22 24 try: … … 24 26 except (ValueError, TypeError): 25 27 self._cull_frequency = 3 26 28 27 29 self._dir = dir 28 30 if not os.path.exists(self._dir): … … 32 34 if self.has_key(key): 33 35 return None 34 36 35 37 self.set(key, value, timeout) 36 38 … … 53 55 fname = self._key_to_file(key) 54 56 dirname = os.path.dirname(fname) 55 57 56 58 if timeout is None: 57 59 timeout = self.default_timeout 58 60 59 61 self._cull() 60 62 61 63 try: 62 64 if not os.path.exists(dirname): … … 104 106 if int(self._num_entries) < self._max_entries: 105 107 return 106 108 107 109 try: 108 110 filelist = os.listdir(self._dir) 109 111 except (IOError, OSError): 110 112 return 111 113 112 114 if self._cull_frequency == 0: 113 115 doomed = filelist … … 134 136 bits of the path into directory prefixes to be nice to filesystems 135 137 that have problems with large numbers of files in a directory. 136 138 137 139 Thus, a cache key of "foo" gets turnned into a file named 138 140 ``{cache-dir}ac/bd/18db4cc2f85cedef654fccc4a4d8``. 139 141 """ 140 path = md5 .new(key.encode('utf-8')).hexdigest()142 path = md5_constructor(key.encode('utf-8')).hexdigest() 141 143 path = os.path.join(path[:2], path[2:4], path[4:]) 142 144 return os.path.join(self._dir, path) … … 148 150 return count 149 151 _num_entries = property(_get_num_entries) 150 django/branches/gis/django/core/cache/backends/locmem.py
r6920 r8215 108 108 doomed = [k for (i, k) in enumerate(self._cache) if i % self._cull_frequency == 0] 109 109 for k in doomed: 110 self. delete(k)110 self._delete(k) 111 111 112 112 def _delete(self, key): django/branches/gis/django/core/cache/__init__.py
r6920 r8215 20 20 from django.core.cache.backends.base import InvalidCacheBackendError 21 21 22 # Name for use in settings file --> name of module in "backends" directory. 23 # Any backend scheme that is not in this dictionary is treated as a Python 24 # import path to a custom backend. 22 25 BACKENDS = { 23 # name for use in settings file --> name of module in "backends" directory24 26 'memcached': 'memcached', 25 27 'locmem': 'locmem', … … 27 29 'db': 'db', 28 30 'dummy': 'dummy', 29 }30 31 DEPRECATED_BACKENDS = {32 # deprecated backend --> replacement module33 'simple': 'locmem',34 31 } 35 32 … … 40 37 if not rest.startswith('//'): 41 38 raise InvalidCacheBackendError, "Backend URI must start with scheme://" 42 if scheme in DEPRECATED_BACKENDS:43 import warnings44 warnings.warn("'%s' backend is deprecated. Use '%s' instead." %45 (scheme, DEPRECATED_BACKENDS[scheme]), DeprecationWarning)46 scheme = DEPRECATED_BACKENDS[scheme]47 if scheme not in BACKENDS:48 raise InvalidCacheBackendError, "%r is not a valid cache backend" % scheme49 39 50 40 host = rest[2:] … … 58 48 host = host[:-1] 59 49 60 cache_class = getattr(__import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']), 'CacheClass') 61 return cache_class(host, params) 50 if scheme in BACKENDS: 51 module = __import__('django.core.cache.backends.%s' % BACKENDS[scheme], {}, {}, ['']) 52 else: 53 module = __import__(scheme, {}, {}, ['']) 54 return getattr(module, 'CacheClass')(host, params) 62 55 63 56 cache = get_cache(settings.CACHE_BACKEND)
