Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Malcolm Tredinnick authored May 08, 2007
3  django/core/cache/backends/base.py
@@ -54,3 +54,6 @@ def has_key(self, key):
54 54
         Returns True if the key is in the cache and has not expired.
55 55
         """
56 56
         return self.get(key) is not None
  57
+
  58
+    __contains__ = has_key
  59
+
5  tests/regressiontests/cache/tests.py
@@ -46,6 +46,11 @@ def test_has_key(self):
46 46
         self.assertEqual(cache.has_key("hello"), True)
47 47
         self.assertEqual(cache.has_key("goodbye"), False)
48 48
 
  49
+    def test_in(self): 
  50
+        cache.set("hello", "goodbye") 
  51
+        self.assertEqual("hello" in cache, True) 
  52
+        self.assertEqual("goodbye" in cache, False) 
  53
+
49 54
     def test_data_types(self):
50 55
         # test data types
51 56
         stuff = {

0 notes on commit 0839a00

Please sign in to comment.
Something went wrong with that request. Please try again.