ATLAS Offline Software
Loading...
Searching...
No Matches
cached.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from functools import wraps
4
5
6def cached(func):
7 """! Decorator to cache function return value.
8
9 @param func Function being cached
10
11 @author James Robinson <james.robinson@cern.ch>
12 """
13 cache = {}
14
15 @wraps(func)
16 def wrapped_f(*args):
17 if args in cache:
18 return cache[args]
19 else:
20 return_value = func(*args)
21 cache[args] = return_value
22 return return_value
23 return wrapped_f