Skip to main content

AutoRefresh

This class provides automatic refreshing of items, combining regular GetOrCreate and Delete operations with background asynchronous refresh. Callers provide callbacks for creating, refreshing, and deleting items, but the cache does not offer APIs to update existing items.

Methods​


Start()​

@classmethod
def Start(
ctx: context.Context
) - > error

Starts background refresh of items. To shutdown the cache, cancel the context.

Parameters​

NameTypeDescription
ctxcontext.ContextThe context used to control the lifecycle of the background refresh. Cancelling this context will shut down the cache.

Returns​

TypeDescription
errorAn error if the background refresh cannot be started.

Get()​

@classmethod
def Get(
id: ItemID
) - > ([Item](../cache/item.md?sid=flytestdlib_cache_item), error)

Get item by id.

Parameters​

NameTypeDescription
idItemIDThe unique identifier of the item to retrieve.

Returns​

TypeDescription
([Item](../cache/item.md?sid=flytestdlib_cache_item), error)The requested Item and an error if the item is not found or an issue occurs during retrieval.

GetOrCreate()​

@classmethod
def GetOrCreate(
id: ItemID,
item: [Item](../cache/item.md?sid=flytestdlib_cache_item)
) - > ([Item](../cache/item.md?sid=flytestdlib_cache_item), error)

Get object if exists else create it.

Parameters​

NameTypeDescription
idItemIDThe unique identifier for the item to get or create.
item[Item](../cache/item.md?sid=flytestdlib_cache_item)The item to create if an item with the given ID does not already exist.

Returns​

TypeDescription
([Item](../cache/item.md?sid=flytestdlib_cache_item), error)The existing item if found, or the newly created item, along with an error if creation fails.

DeleteDelayed()​

@classmethod
def DeleteDelayed(
id: ItemID
) - > error

DeleteDelayed queues an item for deletion. It Will get deleted as part of the next Sync cycle. Until the next sync cycle runs, Get and GetOrCreate will continue to return the Item in its previous state.

Parameters​

NameTypeDescription
idItemIDThe unique identifier of the item to mark for delayed deletion.

Returns​

TypeDescription
errorAn error if the item cannot be queued for deletion.