本文整理汇总了Python中werkzeug.contrib.cache.SimpleCache.clear方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCache.clear方法的具体用法?Python SimpleCache.clear怎么用?Python SimpleCache.clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.cache.SimpleCache
的用法示例。
在下文中一共展示了SimpleCache.clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImageSimpleCache
# 需要导入模块: from werkzeug.contrib.cache import SimpleCache [as 别名]
# 或者: from werkzeug.contrib.cache.SimpleCache import clear [as 别名]
class ImageSimpleCache(ImageCache):
"""Simple image cache."""
def __init__(self):
"""Initialize the cache."""
super(ImageSimpleCache, self).__init__()
self.cache = SimpleCache()
def get(self, key):
"""Return the key value.
:param key: the object's key
:return: the stored object
:rtype: `BytesIO` object
"""
return self.cache.get(key)
def set(self, key, value, timeout=None):
"""Cache the object.
:param key: the object's key
:param value: the stored object
:type value: `BytesIO` object
:param timeout: the cache timeout in seconds
"""
timeout = timeout if timeout else self.timeout
self.cache.set(key, value, timeout)
def delete(self, key):
"""Delete the specific key."""
self.cache.delete(key)
def flush(self):
"""Flush the cache."""
self.cache.clear()
示例2: RecacheTestCase
# 需要导入模块: from werkzeug.contrib.cache import SimpleCache [as 别名]
# 或者: from werkzeug.contrib.cache.SimpleCache import clear [as 别名]
class RecacheTestCase(unittest.TestCase):
def setUp(self):
self.recached = False
def dispatcher(salt):
self.recached = True
self.c = SimpleCache()
cfg = Config(preemptive_recache_seconds=10, preemptive_recache_callback=dispatcher)
self.s = Store(self.c, cfg)
self.r = Retrieval(self.c, cfg)
def test_preemptive_recaching_predicate(self):
m = Metadata(HeaderSet(('foo', 'bar')), 'qux')
def mkretr(**kwargs):
return Retrieval(self.c, Config(**kwargs))
with a.test_request_context('/'):
self.assertFalse(mkretr(preemptive_recache_seconds=10).should_recache_preemptively(10, m))
self.assertFalse(mkretr(preemptive_recache_callback=lambda x: 0).should_recache_preemptively(10, m))
self.assertFalse(self.r.should_recache_preemptively(11, m))
self.assertTrue(self.r.should_recache_preemptively(10, m))
self.assertFalse(self.r.should_recache_preemptively(10, m))
self.c.clear()
self.assertTrue(self.r.should_recache_preemptively(10, m))
def test_preemptive_recaching_cache_bypass(self):
fresh = Response('foo')
with a.test_request_context('/foo'):
self.s.cache_response(fresh)
metadata = self.r.fetch_metadata()
with a.test_request_context('/foo'):
cached = self.r.fetch_response()
self.assertEquals(cached.headers[self.r.X_CACHE_HEADER], 'hit')
with a.test_request_context('/foo', headers={RECACHE_HEADER: metadata.salt}):
self.assertRaises(RecacheRequested, self.r.fetch_response)
with a.test_request_context('/foo', headers={RECACHE_HEADER: 'incorrect-salt'}):
try:
self.r.fetch_response()
except RecacheRequested:
self.fail('unexpected RecacheRequested for incorrect salt')