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


Python SimpleCache.delete方法代碼示例

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

示例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)
開發者ID:carylF,項目名稱:PCB,代碼行數:29,代碼來源:sessions.py


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