示例#1
0
文件: cache.py 项目: andy-li/PyWeb
    def wrapper(func, self, *args, **kwargs):
        now = datetime.now()
        if key:
            c = key
        else:
            c = self.__class__.__name__ + func.__name__
            
        k, handler = key_gen(self, c, anonymous, *args, **kwargs)
        
        value = Cache().findby_key(k)
        
        if _valid_cache(value, handler, anonymous, now):
            return value["value"]
        else:
            val = func(self, *args, **kwargs)
            c = Cache()
            # need key, or save will not work
            c.key = k
            c.value = val
            c.expire = now + timedelta(seconds=expire)

            if value:
                c.save(value["_id"])
            else:
                c.insert()

            return val
示例#2
0
文件: cache.py 项目: andy-li/PyWeb
def remove(key):
    """Remove a cache's value."""
    c = Cache()
    v = c.findby_key(key)
    if v:
        c.remove(v["_id"])