Skip to main content

AutoRefreshCache

This class provides an auto-refreshing cache with regular GetOrCreate and Delete operations, along with background asynchronous refresh. Callers provide callbacks for creating, refreshing, and deleting items. The cache does not provide APIs to update items.

Methods


Start()

@classmethod
def Start(
ctx: context.Context
)

starts background refresh of items

Parameters

NameTypeDescription
ctxcontext.ContextThe context for controlling the background refresh operation's lifecycle.

Get()

@classmethod
def Get(
id: string
) - > [CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem)

Get item by id if exists else null

Parameters

NameTypeDescription
idstringThe unique identifier of the cache item to retrieve.

Returns

TypeDescription
[CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem)The CacheItem associated with the given ID, or null if not found.

GetOrCreate()

@classmethod
def GetOrCreate(
item: [CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem)
) - > ([CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem), error)

Get object if exists else create it

Parameters

NameTypeDescription
item[CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem)The CacheItem to create if an item with the same identifier does not already exist in the cache.

Returns

TypeDescription
([CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem), error)The existing or newly created CacheItem, and an error if the operation failed.