[docs]classEnumCache:""" Lazily-loaded cache for accessing details of an enumeration. """def__init__(self,client:AtlanClient):self.client:AtlanClient=clientself.cache_by_name:Dict[str,EnumDef]={}self.lock:Lock=Lock()
[docs]defget_by_name(self,name:str)->EnumDef:""" Retrieve the enumeration definition by its name. :param name: human-readable name of the enumeration. :raises `NotFoundError`: if the enumeration with the given name does not exist. :returns: enumeration definition """ifnot(enum:=self._get_by_name(name=name)):raiseErrorCode.ENUM_NOT_FOUND.exception_with_parameters(name)returnenum
[docs]defrefresh_cache(self)->None:""" Refreshes the cache of enumerations by requesting the full set of enumerations from Atlan. """withself.lock:response=self.client.typedef.get(type_category=AtlanTypeCategory.ENUM)ifnotresponseornotresponse.enum_defs:raiseErrorCode.EXPIRED_API_TOKEN.exception_with_parameters()self.cache_by_name={}ifresponseisnotNone:forenuminresponse.enum_defs:type_name=enum.nameself.cache_by_name[type_name]=enum
def_get_by_name(self,name:str)->Optional[EnumDef]:""" Retrieve the enumeration definition by its name. :param name: human-readable name of the enumeration :returns: the enumeration definition """ifname:ifenum_def:=self.cache_by_name.get(name):returnenum_defself.refresh_cache()returnself.cache_by_name.get(name)returnNone