Author: jezdez
Date: 2012-02-09 10:58:25 -0800 (Thu, 09 Feb 2012)
New Revision: 17479

Modified:
   django/trunk/django/core/cache/__init__.py
   django/trunk/tests/regressiontests/cache/tests.py
Log:
Fixed #17286 -- Made sure all cache backends are set up to connect to the 
signal handler that closes the cache connection when the request has been 
processed. Thanks, gnosek.

Modified: django/trunk/django/core/cache/__init__.py
===================================================================
--- django/trunk/django/core/cache/__init__.py  2012-02-09 18:58:17 UTC (rev 
17478)
+++ django/trunk/django/core/cache/__init__.py  2012-02-09 18:58:25 UTC (rev 
17479)
@@ -176,12 +176,13 @@
     except (AttributeError, ImportError), e:
         raise InvalidCacheBackendError(
             "Could not find backend '%s': %s" % (backend, e))
-    return backend_cls(location, params)
+    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)
+    return cache
 
 cache = get_cache(DEFAULT_CACHE_ALIAS)
 
-# 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)

Modified: django/trunk/tests/regressiontests/cache/tests.py
===================================================================
--- django/trunk/tests/regressiontests/cache/tests.py   2012-02-09 18:58:17 UTC 
(rev 17478)
+++ django/trunk/tests/regressiontests/cache/tests.py   2012-02-09 18:58:25 UTC 
(rev 17479)
@@ -1040,7 +1040,14 @@
 
         self.assertRaises(InvalidCacheBackendError, get_cache, 
'does_not_exist')
 
+    def test_close(self):
+        from django.core import signals
+        cache = get_cache('regressiontests.cache.closeable_cache.CacheClass')
+        self.assertFalse(cache.closed)
+        signals.request_finished.send(self.__class__)
+        self.assertTrue(cache.closed)
 
+
 class CacheUtils(TestCase):
     """TestCase for django.utils.cache functions."""
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to