Ticket #5133: memcached-cleanup-connections.patch

File memcached-cleanup-connections.patch, 1.3 KB (added by Jacob, 17 years ago)
  • django/core/cache/__init__.py

    diff -r 4e09c07db18b django/core/cache/__init__.py
    a b See docs/cache.txt for information on th  
    1717
    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
    2123
    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)
    5355
    5456cache = get_cache(settings.CACHE_BACKEND)
     57
     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/memcached.py

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