ATLAS Offline Software
Generators
PowhegControl
python
decorators
cached.py
Go to the documentation of this file.
1
# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3
from
functools
import
wraps
4
5
6
def
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
python.decorators.cached.cached
def cached(func)
Decorator to cache function return value.
Definition:
cached.py:6
Generated on Sun Dec 22 2024 21:07:39 for ATLAS Offline Software by
1.8.18