summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Manfre <mmanfre@gmail.com>2014-11-06 23:47:04 -0500
committerMichael Manfre <mmanfre@gmail.com>2014-11-13 00:46:03 -0500
commitbc8abe36ba5508fe788f6d49a26749268d368583 (patch)
tree8ba53f287e0fef913f60905a20abf34fa6db011b /tests
parentbfb11b95626f39e2f5e18d97d7761c6f93dcc1a9 (diff)
Fixed #16358 - Made memcache backend delete old value on a failure to set.
Default Memcached configuration allows for a maximum object of 1MB and will fail to set the key if it is too large. The key will be deleted from memcached if it fails to be set. This is needed to avoid an issue with cache_db session backend using the old value stored in memcached, instead of the newer value stored in the database.
Diffstat (limited to 'tests')
-rw-r--r--tests/cache/tests.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/cache/tests.py b/tests/cache/tests.py
index c7604f131e..9dfd7af15d 100644
--- a/tests/cache/tests.py
+++ b/tests/cache/tests.py
@@ -1133,6 +1133,24 @@ class MemcachedCacheTests(BaseCacheTests, TestCase):
# culling isn't implemented, memcached deals with it.
pass
+ def test_memcached_deletes_key_on_failed_set(self):
+ # By default memcached allows objects up to 1MB. For the cache_db session
+ # backend to always use the current session, memcached needs to delete
+ # the old key if it fails to set.
+ # pylibmc doesn't seem to have SERVER_MAX_VALUE_LENGTH as far as I can
+ # tell from a quick check of its source code. This is falling back to
+ # the default value exposed by python-memcached on my system.
+ max_value_length = getattr(cache._lib, 'SERVER_MAX_VALUE_LENGTH', 1048576)
+
+ cache.set('small_value', 'a')
+ self.assertEqual(cache.get('small_value'), 'a')
+
+ large_value = 'a' * (max_value_length + 1)
+ cache.set('small_value', large_value)
+ # small_value should be deleted, or set if configured to accept larger values
+ value = cache.get('small_value')
+ self.assertTrue(value is None or value == large_value)
+
@override_settings(CACHES=caches_setting_for_tests(
BACKEND='django.core.cache.backends.filebased.FileBasedCache',