from functools import wraps

def cache(func):
    data = {}
    @wraps(func)
    def wrapper(*args):
        if args in data:
            print "in cache"
            return data[args]
        else:
            print "not in cache"
            res = func(*args)
            data[args] = res
            return res
    return wrapper

@cache
def post_data(args):
    return args

post_data(123)    # not in cache
post_data(123)    # in cache
post_data(1235)    # not in cache

 

相关文章:

  • 2021-05-07
  • 2021-05-25
  • 2021-04-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-03-10
  • 2022-03-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-12-23
相关资源
相似解决方案