]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/Common/caching.py
2 # help with caching in BaseTools
4 # Copyright (c) 2018, Intel Corporation. All rights reserved.<BR>
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
13 class cached_class_function(object):
14 def __init__(self
, function
):
15 self
._function
= function
16 def __get__(self
, obj
, cls
):
17 def CallMeHere(*args
,**kwargs
):
18 Value
= self
._function
(obj
, *args
,**kwargs
)
19 obj
.__dict
__[self
._function
.__name
__] = lambda *args
,**kwargs
:Value
24 class cached_property(object):
25 def __init__(self
, function
):
26 self
._function
= function
27 def __get__(self
, obj
, cls
):
28 Value
= obj
.__dict
__[self
._function
.__name
__] = self
._function
(obj
)
31 # for non-class function
32 class cached_basic_function(object):
33 def __init__(self
, function
):
34 self
._function
= function
35 # wrapper to call _do since <class>.__dict__ doesn't support changing __call__
36 def __call__(self
,*args
,**kwargs
):
37 return self
._do
(*args
,**kwargs
)
38 def _do(self
,*args
,**kwargs
):
39 Value
= self
._function
(*args
,**kwargs
)
40 self
.__dict
__['_do'] = lambda self
,*args
,**kwargs
:Value