当前位置: 首页>>代码示例>>Python>>正文


Python GenericCache.delete方法代码示例

本文整理汇总了Python中MaKaC.common.cache.GenericCache.delete方法的典型用法代码示例。如果您正苦于以下问题:Python GenericCache.delete方法的具体用法?Python GenericCache.delete怎么用?Python GenericCache.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MaKaC.common.cache.GenericCache的用法示例。


在下文中一共展示了GenericCache.delete方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wrapper

# 需要导入模块: from MaKaC.common.cache import GenericCache [as 别名]
# 或者: from MaKaC.common.cache.GenericCache import delete [as 别名]
 def wrapper(*args, **kwargs):
     cache = GenericCache('task-locks')
     name = current_task.name
     if cache.get(name):
         Logger.get('celery').warning('Task {} is locked; not executing it'.format(name))
         return
     cache.set(name, True)
     try:
         return f(*args, **kwargs)
     finally:
         cache.delete(name)
开发者ID:dbourillot,项目名称:indico,代码行数:13,代码来源:util.py

示例2: SudsCache

# 需要导入模块: from MaKaC.common.cache import GenericCache [as 别名]
# 或者: from MaKaC.common.cache.GenericCache import delete [as 别名]
class SudsCache(Cache):
    _instance = None

    def __init__(self, duration=DEFAULT_CACHE_TTL):
        self._cache = GenericCache("SudsCache")
        self._duration = duration

    def get(self, key):
        self._cache.get(key)

    def put(self, key, val):
        self._cache.set(key, val, self._duration)

    def purge(self, key):
        self._cache.delete(key)
开发者ID:florv,项目名称:indico-plugins,代码行数:17,代码来源:cache.py

示例3: SudsCache

# 需要导入模块: from MaKaC.common.cache import GenericCache [as 别名]
# 或者: from MaKaC.common.cache.GenericCache import delete [as 别名]
class SudsCache(Cache):
    _instance = None

    @classmethod
    def getInstance(cls, duration=None):
        if cls._instance is None:
            cls._instance = SudsCache(duration)
        return cls._instance

    def __init__(self, duration=None):
        self._cache = GenericCache("SudsCache")
        if duration is None:
            duration = 24 * 3600 # we put as default 1 day cache
        self._duration = duration

    def get(self, key):
        self._cache.get(key)

    def put(self, key, val):
        self._cache.set(key, val, self._duration)

    def purge(self, key):
        self._cache.delete(key)
开发者ID:Ictp,项目名称:indico,代码行数:25,代码来源:cache.py

示例4: IndicoSessionInterface

# 需要导入模块: from MaKaC.common.cache import GenericCache [as 别名]
# 或者: from MaKaC.common.cache.GenericCache import delete [as 别名]
class IndicoSessionInterface(SessionInterface):
    pickle_based = True
    serializer = cPickle
    session_class = IndicoSession
    temporary_session_lifetime = timedelta(days=7)

    def __init__(self):
        self.storage = GenericCache('flask-session')

    def generate_sid(self):
        return str(uuid.uuid4())

    def get_cookie_secure(self, app):
        return request.is_secure

    def get_storage_lifetime(self, app, session):
        # Permanent sessions are stored for exactly the same duration as the session id cookie.
        # "Temporary" session are stored for a period that is not too short/long as some people
        # close their browser very rarely and thus shouldn't be logged out that often.
        if session.permanent:
            return app.permanent_session_lifetime
        else:
            return self.temporary_session_lifetime

    def should_refresh_session(self, app, session):
        if session.new or '_expires' not in session:
            return False
        threshold = self.get_storage_lifetime(app, session) / 2
        return session['_expires'] - datetime.now() < threshold

    def should_refresh_sid(self, app, session):
        return self.get_cookie_secure(app) and not session.get('_secure')

    def open_session(self, app, request):
        sid = request.cookies.get(app.session_cookie_name)
        if not sid:
            return self.session_class(sid=self.generate_sid(), new=True)
        data = self.storage.get(sid)
        if data is not None:
            return self.session_class(self.serializer.loads(data), sid=sid)
        return self.session_class(sid=self.generate_sid(), new=True)

    def save_session(self, app, session, response):
        domain = self.get_cookie_domain(app)
        secure = self.get_cookie_secure(app)
        refresh_sid = self.should_refresh_sid(app, session)
        if not session and not session.new:
            # empty session, delete it from storage and cookie
            self.storage.delete(session.sid)
            response.delete_cookie(app.session_cookie_name, domain=domain)
            return

        if not refresh_sid and not session.modified and not self.should_refresh_session(app, session):
            # If the session has not been modified we only store if it needs to be refreshed
            return

        if app.config['INDICO_SESSION_PERMANENT']:
            # Setting session.permanent marks the session as modified so we only set it when we
            # are saving the session anyway!
            session.permanent = True

        storage_ttl = self.get_storage_lifetime(app, session)
        cookie_lifetime = self.get_expiration_time(app, session)
        session['_expires'] = datetime.now() + storage_ttl

        if refresh_sid:
            self.storage.delete(session.sid)
            session.sid = self.generate_sid()

        session['_secure'] = request.is_secure
        self.storage.set(session.sid, self.serializer.dumps(dict(session)), storage_ttl)
        response.set_cookie(app.session_cookie_name, session.sid, expires=cookie_lifetime, httponly=True,
                            secure=secure)
开发者ID:k3njiy,项目名称:indico,代码行数:75,代码来源:session.py


注:本文中的MaKaC.common.cache.GenericCache.delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。