Fixed #28760 -- Removed DummyCache's unnecessary get/set/delete_many().
This commit is contained in:
parent
23e551ce6c
commit
acc989f037
|
@ -25,19 +25,10 @@ class DummyCache(BaseCache):
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
|
|
||||||
def get_many(self, keys, version=None):
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def has_key(self, key, version=None):
|
def has_key(self, key, version=None):
|
||||||
key = self.make_key(key, version=version)
|
key = self.make_key(key, version=version)
|
||||||
self.validate_key(key)
|
self.validate_key(key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def set_many(self, data, timeout=DEFAULT_TIMEOUT, version=None):
|
|
||||||
return []
|
|
||||||
|
|
||||||
def delete_many(self, keys, version=None):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -59,6 +59,12 @@ class Unpicklable:
|
||||||
raise pickle.PickleError()
|
raise pickle.PickleError()
|
||||||
|
|
||||||
|
|
||||||
|
KEY_ERRORS_WITH_MEMCACHED_MSG = (
|
||||||
|
'Cache key contains characters that will cause errors if used with '
|
||||||
|
'memcached: %r'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(CACHES={
|
@override_settings(CACHES={
|
||||||
'default': {
|
'default': {
|
||||||
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
|
||||||
|
@ -94,6 +100,10 @@ class DummyCacheTests(SimpleTestCase):
|
||||||
self.assertEqual(cache.get_many(['a', 'c', 'd']), {})
|
self.assertEqual(cache.get_many(['a', 'c', 'd']), {})
|
||||||
self.assertEqual(cache.get_many(['a', 'b', 'e']), {})
|
self.assertEqual(cache.get_many(['a', 'b', 'e']), {})
|
||||||
|
|
||||||
|
def test_get_many_invalid_key(self):
|
||||||
|
with self.assertWarns(CacheKeyWarning, msg=KEY_ERRORS_WITH_MEMCACHED_MSG % 'key with spaces'):
|
||||||
|
cache.get_many(['key with spaces'])
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
"Cache deletion is transparently ignored on the dummy cache backend"
|
"Cache deletion is transparently ignored on the dummy cache backend"
|
||||||
cache.set("key1", "spam")
|
cache.set("key1", "spam")
|
||||||
|
@ -176,10 +186,18 @@ class DummyCacheTests(SimpleTestCase):
|
||||||
self.assertEqual(cache.set_many({'a': 1, 'b': 2}), [])
|
self.assertEqual(cache.set_many({'a': 1, 'b': 2}), [])
|
||||||
self.assertEqual(cache.set_many({'a': 1, 'b': 2}, timeout=2, version='1'), [])
|
self.assertEqual(cache.set_many({'a': 1, 'b': 2}, timeout=2, version='1'), [])
|
||||||
|
|
||||||
|
def test_set_many_invalid_key(self):
|
||||||
|
with self.assertWarns(CacheKeyWarning, msg=KEY_ERRORS_WITH_MEMCACHED_MSG % 'key with spaces'):
|
||||||
|
cache.set_many({'key with spaces': 'foo'})
|
||||||
|
|
||||||
def test_delete_many(self):
|
def test_delete_many(self):
|
||||||
"delete_many does nothing for the dummy cache backend"
|
"delete_many does nothing for the dummy cache backend"
|
||||||
cache.delete_many(['a', 'b'])
|
cache.delete_many(['a', 'b'])
|
||||||
|
|
||||||
|
def test_delete_many_invalid_key(self):
|
||||||
|
with self.assertWarns(CacheKeyWarning, msg=KEY_ERRORS_WITH_MEMCACHED_MSG % 'key with spaces'):
|
||||||
|
cache.delete_many({'key with spaces': 'foo'})
|
||||||
|
|
||||||
def test_clear(self):
|
def test_clear(self):
|
||||||
"clear does nothing for the dummy cache backend"
|
"clear does nothing for the dummy cache backend"
|
||||||
cache.clear()
|
cache.clear()
|
||||||
|
@ -596,11 +614,7 @@ class BaseCacheTests:
|
||||||
def test_invalid_key_characters(self):
|
def test_invalid_key_characters(self):
|
||||||
# memcached doesn't allow whitespace or control characters in keys.
|
# memcached doesn't allow whitespace or control characters in keys.
|
||||||
key = 'key with spaces and 清'
|
key = 'key with spaces and 清'
|
||||||
expected_warning = (
|
self._perform_invalid_key_test(key, KEY_ERRORS_WITH_MEMCACHED_MSG % key)
|
||||||
"Cache key contains characters that will cause errors if used "
|
|
||||||
"with memcached: %r" % key
|
|
||||||
)
|
|
||||||
self._perform_invalid_key_test(key, expected_warning)
|
|
||||||
|
|
||||||
def test_invalid_key_length(self):
|
def test_invalid_key_length(self):
|
||||||
# memcached limits key length to 250.
|
# memcached limits key length to 250.
|
||||||
|
|
Loading…
Reference in New Issue