mirror of
https://github.com/django/django.git
synced 2024-12-23 09:36:06 +00:00
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
This commit is contained in:
parent
d1b0d34dc6
commit
0839a0046a
3
django/core/cache/backends/base.py
vendored
3
django/core/cache/backends/base.py
vendored
@ -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
|
||||
|
||||
|
5
tests/regressiontests/cache/tests.py
vendored
5
tests/regressiontests/cache/tests.py
vendored
@ -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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user