mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Merge pull request #218 from mgrouchy/ticket_18582
Fixed #18582 -- Added a no-op close to BaseCache
This commit is contained in:
8
django/core/cache/__init__.py
vendored
8
django/core/cache/__init__.py
vendored
@@ -134,11 +134,9 @@ def get_cache(backend, **kwargs):
|
||||
"Could not find backend '%s': %s" % (backend, e))
|
||||
cache = backend_cls(location, params)
|
||||
# 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'):
|
||||
signals.request_finished.connect(cache.close)
|
||||
# end of a request cycle. If not implemented in a particular backend
|
||||
# cache.close is a no-op
|
||||
signals.request_finished.connect(cache.close)
|
||||
return cache
|
||||
|
||||
cache = get_cache(DEFAULT_CACHE_ALIAS)
|
||||
|
||||
|
||||
9
django/core/cache/backends/base.py
vendored
9
django/core/cache/backends/base.py
vendored
@@ -6,15 +6,18 @@ import warnings
|
||||
from django.core.exceptions import ImproperlyConfigured, DjangoRuntimeWarning
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
|
||||
class InvalidCacheBackendError(ImproperlyConfigured):
|
||||
pass
|
||||
|
||||
|
||||
class CacheKeyWarning(DjangoRuntimeWarning):
|
||||
pass
|
||||
|
||||
# Memcached does not accept keys longer than this.
|
||||
MEMCACHE_MAX_KEY_LENGTH = 250
|
||||
|
||||
|
||||
def default_key_func(key, key_prefix, version):
|
||||
"""
|
||||
Default function to generate keys.
|
||||
@@ -25,6 +28,7 @@ def default_key_func(key, key_prefix, version):
|
||||
"""
|
||||
return ':'.join([key_prefix, str(version), key])
|
||||
|
||||
|
||||
def get_key_func(key_func):
|
||||
"""
|
||||
Function to decide which key function to use.
|
||||
@@ -40,6 +44,7 @@ def get_key_func(key_func):
|
||||
return getattr(key_func_module, key_func_name)
|
||||
return default_key_func
|
||||
|
||||
|
||||
class BaseCache(object):
|
||||
def __init__(self, params):
|
||||
timeout = params.get('timeout', params.get('TIMEOUT', 300))
|
||||
@@ -221,3 +226,7 @@ class BaseCache(object):
|
||||
the new version.
|
||||
"""
|
||||
return self.incr_version(key, -delta, version)
|
||||
|
||||
def close(self, **kwargs):
|
||||
"""Close the cache connection"""
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user