本文整理汇总了Python中werkzeug.contrib.cache.SimpleCache.delete方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleCache.delete方法的具体用法?Python SimpleCache.delete怎么用?Python SimpleCache.delete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.contrib.cache.SimpleCache
的用法示例。
在下文中一共展示了SimpleCache.delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ImageSimpleCache
# 需要导入模块: from werkzeug.contrib.cache import SimpleCache [as 别名]
# 或者: from werkzeug.contrib.cache.SimpleCache import delete [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: _UserSessions
# 需要导入模块: from werkzeug.contrib.cache import SimpleCache [as 别名]
# 或者: from werkzeug.contrib.cache.SimpleCache import delete [as 别名]
class _UserSessions(object):
def __init__(self):
self.cache = SimpleCache()
def create(self, user_id):
user = User.find(User.id == user_id)
if user is None:
return None
sess = os.urandom(24)
self.cache.set(sess, user_id)
session['key'] = sess
return sess
def get(self):
if 'key' not in session:
return None
key = session['key']
user_id = self.cache.get(key)
user = User.find(User.id == user_id)
session['user'] = user
return user
def delete(self):
if 'key' in session:
self.cache.delete(session['key'])
session.pop('key', None)
session.pop('user', None)