Ticket #16006: lazycache.diff
File lazycache.diff, 1.5 KB (added by , 14 years ago) |
---|
-
django/core/cache/__init__.py
20 20 InvalidCacheBackendError, CacheKeyWarning, BaseCache) 21 21 from django.core.exceptions import ImproperlyConfigured 22 22 from django.utils import importlib 23 from django.utils.functional import SimpleLazyObject 23 24 24 25 try: 25 26 # The mod_python version is more efficient, so try importing it first. … … 177 178 except (AttributeError, ImportError), e: 178 179 raise InvalidCacheBackendError( 179 180 "Could not find backend '%s': %s" % (backend, e)) 180 return backend_cls(location, params) 181 cache = backend_cls(location, params) 182 # Some caches -- python-memcached in particular -- need to do a cleanup at the 183 # end of a request cycle. If the cache provides a close() method, wire it up 184 # here. 185 if hasattr(cache, 'close'): 186 signals.request_finished.connect(cache.close, dispatch_uid='%s.%s' % (backend_cls.__module__, backend_cls.__name__)) 187 return cache 181 188 182 cache = get_cache(DEFAULT_CACHE_ALIAS) 183 184 # Some caches -- python-memcached in particular -- need to do a cleanup at the 185 # end of a request cycle. If the cache provides a close() method, wire it up 186 # here. 187 if hasattr(cache, 'close'): 188 signals.request_finished.connect(cache.close) 189 cache = SimpleLazyObject(lambda: get_cache(DEFAULT_CACHE_ALIAS))