diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-11-19 15:39:35 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-11-19 15:39:35 +0000 |
| commit | 99d247f4cb0c22d19a4482a72a7a93584a5189da (patch) | |
| tree | ed15204640bb1f34a2627a3ce7950047e22acd82 /django/core/cache/__init__.py | |
| parent | 261aee26c19a0d452847611502201088c14a1c19 (diff) | |
Fixed #13795 -- Added a site-wide cache prefix and cache versioning. Thanks to bruth for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@14623 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core/cache/__init__.py')
| -rw-r--r-- | django/core/cache/__init__.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py index 7c3f0927eb..d26eabd0c3 100644 --- a/django/core/cache/__init__.py +++ b/django/core/cache/__init__.py @@ -67,18 +67,30 @@ def parse_backend_uri(backend_uri): return scheme, host, params -def get_cache(backend_uri): +def get_cache(backend_uri, key_prefix=None, version=None, key_func=None): + if key_prefix is None: + key_prefix = settings.CACHE_KEY_PREFIX + if version is None: + version = settings.CACHE_VERSION + if key_func is None: + key_func = settings.CACHE_KEY_FUNCTION + + if key_func is not None and not callable(key_func): + key_func_module_path, key_func_name = key_func.rsplit('.', 1) + key_func_module = importlib.import_module(key_func_module_path) + key_func = getattr(key_func_module, key_func_name) + scheme, host, params = parse_backend_uri(backend_uri) if scheme in BACKENDS: name = 'django.core.cache.backends.%s' % BACKENDS[scheme] else: name = scheme module = importlib.import_module(name) - return module.CacheClass(host, params) + return module.CacheClass(host, params, key_prefix=key_prefix, version=version, key_func=key_func) cache = get_cache(settings.CACHE_BACKEND) -# Some caches -- pythont-memcached in particular -- need to do a cleanup at the +# Some caches -- python-memcached in particular -- need to do a cleanup at the # end of a request cycle. If the cache provides a close() method, wire it up # here. if hasattr(cache, 'close'): |
