當前位置: 首頁>>代碼示例>>Python>>正文


Python SimpleCache.clear方法代碼示例

本文整理匯總了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()
開發者ID:inveniosoftware,項目名稱:flask-iiif,代碼行數:37,代碼來源:simple.py

示例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')
開發者ID:fangbei,項目名稱:flask-webcache,代碼行數:41,代碼來源:test_storage.py


注:本文中的werkzeug.contrib.cache.SimpleCache.clear方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。