Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #4041 -- Added a __contains__ method to cache backends. Thanks,…

… Gary

Wilson and SmileyChris.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@5171 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 0839a0046a09bc80a9cfe02dcc462cb9e4dc2521 1 parent d1b0d34
@malcolmt malcolmt authored
View
3  django/core/cache/backends/base.py
@@ -54,3 +54,6 @@ def has_key(self, key):
Returns True if the key is in the cache and has not expired.
"""
return self.get(key) is not None
+
+ __contains__ = has_key
+
View
5 tests/regressiontests/cache/tests.py
@@ -46,6 +46,11 @@ def test_has_key(self):
self.assertEqual(cache.has_key("hello"), True)
self.assertEqual(cache.has_key("goodbye"), False)
+ def test_in(self):
+ cache.set("hello", "goodbye")
+ self.assertEqual("hello" in cache, True)
+ self.assertEqual("goodbye" in cache, False)
+
def test_data_types(self):
# test data types
stuff = {
Please sign in to comment.
Something went wrong with that request. Please try again.