Django

Code

Changeset 8418

Show
Ignore:
Timestamp:
08/16/08 18:35:58 (4 months ago)
Author:
mtredinnick
Message:

Fixed #5133 -- Explicitly close memcached connections after each request
(similar to database connection management). We can't effectively manage the
lifecycle by pooling connections and recent versions of python-memcache can
lead to connection exhaustion in some quite reasonable setups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/cache/backends/memcached.py

    r8278 r8418  
    4040    def get_many(self, keys): 
    4141        return self._cache.get_multi(map(smart_str,keys)) 
     42 
     43    def close(self, **kwargs): 
     44        self._cache.disconnect_all() 
     45 
  • django/trunk/django/core/cache/__init__.py

    r8191 r8418  
    1818from cgi import parse_qsl 
    1919from django.conf import settings 
     20from django.core import signals 
    2021from django.core.cache.backends.base import InvalidCacheBackendError 
    2122 
     
    5556 
    5657cache = get_cache(settings.CACHE_BACKEND) 
     58 
     59# Some caches -- pythont-memcached in particular -- need to do a cleanup at the 
     60# end of a request cycle. If the cache provides a close() method, wire it up 
     61# here. 
     62if hasattr(cache, 'close'): 
     63    signals.request_finished.connect(cache.close) 
     64