From 4529af9ecf7debc9281021462531ec4d9697013b Mon Sep 17 00:00:00 2001 From: Vincent-Vega Date: Mon, 16 Jun 2014 12:46:34 +0400 Subject: [PATCH] Fixed #22845 -- Correctly handled memcached default timeout value. --- django/core/cache/backends/memcached.py | 2 +- tests/cache/tests.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/django/core/cache/backends/memcached.py b/django/core/cache/backends/memcached.py index 0c094f0fde..b32ab704ec 100644 --- a/django/core/cache/backends/memcached.py +++ b/django/core/cache/backends/memcached.py @@ -49,7 +49,7 @@ class BaseMemcachedCache(six.with_metaclass(BaseMemcachedCacheMethods, BaseCache way. Call this function to obtain a safe value for your timeout. """ if timeout == DEFAULT_TIMEOUT: - return self.default_timeout + timeout = self.default_timeout if timeout is None: # Using 0 in memcache sets a non-expiring timeout. diff --git a/tests/cache/tests.py b/tests/cache/tests.py index 05e505470b..d4255e5fa0 100644 --- a/tests/cache/tests.py +++ b/tests/cache/tests.py @@ -1078,6 +1078,12 @@ for _cache_params in settings.CACHES.values(): if _cache_params['BACKEND'].startswith('django.core.cache.backends.memcached.'): memcached_params = _cache_params +memcached_never_expiring_params = memcached_params.copy() +memcached_never_expiring_params['TIMEOUT'] = None + +memcached_far_future_params = memcached_params.copy() +memcached_far_future_params['TIMEOUT'] = 31536000 # 60*60*24*365, 1 year + @unittest.skipUnless(memcached_params, "memcached not available") @override_settings(CACHES=caches_setting_for_tests(base=memcached_params)) @@ -1109,6 +1115,18 @@ class MemcachedCacheTests(BaseCacheTests, TestCase): self.assertEqual(caches[cache_key]._cache.pickleProtocol, pickle.HIGHEST_PROTOCOL) + @override_settings(CACHES=caches_setting_for_tests(base=memcached_never_expiring_params)) + def test_default_never_expiring_timeout(self): + # Regression test for #22845 + cache.set('infinite_foo', 'bar') + self.assertEqual(cache.get('infinite_foo'), 'bar') + + @override_settings(CACHES=caches_setting_for_tests(base=memcached_far_future_params)) + def test_default_far_future_timeout(self): + # Regression test for #22845 + cache.set('future_foo', 'bar') + self.assertEqual(cache.get('future_foo'), 'bar') + def test_cull(self): # culling isn't implemented, memcached deals with it. pass