localcache_decorator

Local cache

code

from xlib.middleware import cache

@cache.cache_page(expire=2)
def add(a, b):
    print("exe add")
    return a + b

if __name__ == "__main__":
    import time
    print add(3, 6)
    print add(3, 6)
    print add(3, 6)
    time.sleep(2)
    print add(3, 6)
    print add(3, 6)
    print add(3, 6)

输出

exe add
9
9
9
exe add
9
9
9

Last updated