diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-08 04:13:46 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-05-08 04:13:46 +0000 |
| commit | 0839a0046a09bc80a9cfe02dcc462cb9e4dc2521 (patch) | |
| tree | 0d41722dfd6ac62677ab922d82ed83134ba13e37 | |
| parent | d1b0d34dc67941ce7c285c29d3f4031954c20283 (diff) | |
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
| -rw-r--r-- | django/core/cache/backends/base.py | 3 | ||||
| -rw-r--r-- | tests/regressiontests/cache/tests.py | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/django/core/cache/backends/base.py b/django/core/cache/backends/base.py index ef5f6a6b3e..bb67399f3b 100644 --- a/django/core/cache/backends/base.py +++ b/django/core/cache/backends/base.py @@ -54,3 +54,6 @@ class BaseCache(object): Returns True if the key is in the cache and has not expired. """ return self.get(key) is not None + + __contains__ = has_key + diff --git a/tests/regressiontests/cache/tests.py b/tests/regressiontests/cache/tests.py index cf58ab321a..9dc7161c03 100644 --- a/tests/regressiontests/cache/tests.py +++ b/tests/regressiontests/cache/tests.py @@ -46,6 +46,11 @@ class Cache(unittest.TestCase): 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 = { |
