ATLAS Offline Software
Functions
python.decorators.cached Namespace Reference

Functions

def cached (func)
 Decorator to cache function return value. More...
 

Function Documentation

◆ cached()

def python.decorators.cached.cached (   func)

Decorator to cache function return value.

Parameters
funcFunction being cached
Author
James Robinson james.nosp@m..rob.nosp@m.inson.nosp@m.@cer.nosp@m.n.ch

Definition at line 6 of file cached.py.

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