From 0839a0046a09bc80a9cfe02dcc462cb9e4dc2521 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Tue, 8 May 2007 04:13:46 +0000 Subject: [PATCH] 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 --- django/core/cache/backends/base.py | 3 +++ tests/regressiontests/cache/tests.py | 5 +++++ 2 files changed, 8 insertions(+) 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 = {