Ticket #5133: memcached-cleanup-connections.patch

File memcached-cleanup-connections.patch, 1.3 KB (added by jacob, 7 years ago)
  • django/core/cache/

    diff -r 4e09c07db18b django/core/cache/
    a b See docs/cache.txt for information on th 
    1818from cgi import parse_qsl 
    1919from django.conf import settings 
     20from django.core import signals 
    2021from django.core.cache.backends.base import InvalidCacheBackendError 
     22from django.dispatch import dispatcher 
    2224BACKENDS = { 
    2325    # name for use in settings file --> name of module in "backends" directory 
    def get_cache(backend_uri): 
    5254    return cache_class(host, params) 
    5456cache = get_cache(settings.CACHE_BACKEND) 
     58# Some caches -- memcached in particular -- need to do cleanup at the end of a 
     59# request cycle. If the cache provides a close() method, wire it up here. 
     60if hasattr(cache, "close"): 
     61    dispatcher.connect(cache.close, signal=signals.request_finished) 
  • django/core/cache/backends/

    diff -r 4e09c07db18b django/core/cache/backends/
    a b class CacheClass(BaseCache): 
    3737    def get_many(self, keys): 
    3838        return self._cache.get_multi(map(smart_str,keys)) 
     40    def close(self): 
     41        self._cache.disconnect_all()