mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Properly closed cache connections at the end of the request.
This only affects the new cache api and not the deprecated get_cache. Refs #21012
This commit is contained in:
parent
8adbfdfcc4
commit
d47f794f8f
2 changed files with 41 additions and 11 deletions
20
tests/cache/tests.py
vendored
20
tests/cache/tests.py
vendored
|
@ -203,7 +203,6 @@ _caches_setting_base = {
|
|||
'custom_key2': {'KEY_FUNCTION': 'cache.tests.custom_key_func'},
|
||||
'cull': {'OPTIONS': {'MAX_ENTRIES': 30}},
|
||||
'zero_cull': {'OPTIONS': {'CULL_FREQUENCY': 0, 'MAX_ENTRIES': 30}},
|
||||
'other': {'LOCATION': 'other'},
|
||||
}
|
||||
|
||||
|
||||
|
@ -1014,6 +1013,13 @@ class LocMemCacheTests(BaseCacheTests, TestCase):
|
|||
caches['custom_key2']._cache = cache._cache
|
||||
caches['custom_key2']._expire_info = cache._expire_info
|
||||
|
||||
@override_settings(CACHES={
|
||||
'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'},
|
||||
'other': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'other'
|
||||
},
|
||||
})
|
||||
def test_multiple_caches(self):
|
||||
"Check that multiple locmem caches are isolated"
|
||||
cache.set('value', 42)
|
||||
|
@ -1139,6 +1145,12 @@ class CustomCacheKeyValidationTests(TestCase):
|
|||
self.assertEqual(cache.get(key), val)
|
||||
|
||||
|
||||
@override_settings(
|
||||
CACHES={
|
||||
'default': {
|
||||
'BACKEND': 'cache.closeable_cache.CacheClass',
|
||||
}
|
||||
},)
|
||||
class GetCacheTests(IgnorePendingDeprecationWarningsMixin, TestCase):
|
||||
|
||||
def test_simple(self):
|
||||
|
@ -1157,6 +1169,12 @@ class GetCacheTests(IgnorePendingDeprecationWarningsMixin, TestCase):
|
|||
self.assertRaises(InvalidCacheBackendError, get_cache, 'does_not_exist')
|
||||
|
||||
def test_close(self):
|
||||
from django.core import signals
|
||||
self.assertFalse(cache.closed)
|
||||
signals.request_finished.send(self.__class__)
|
||||
self.assertTrue(cache.closed)
|
||||
|
||||
def test_close_deprecated(self):
|
||||
from django.core.cache import get_cache
|
||||
from django.core import signals
|
||||
cache = get_cache('cache.closeable_cache.CacheClass')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue