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, as the cache does not offer direct update APIs.
Methods
Start()
@classmethod
def Start(
ctx: context.Context
) - > error
Starts background refresh of items. To shutdown the cache, cancel the context.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The context used to control the lifecycle of the background refresh. Cancelling this context will shut down the cache. |
Returns
| Type | Description |
|---|---|
error | An error if the background refresh cannot be started. |
Get()
@classmethod
def Get(
id: [ItemID](../cache/itemid.md?sid=flytestdlib_cache_itemid)
) - > ([Item](../cache/item.md?sid=flytestdlib_cache_item), error)
Get item by id.
Parameters
| Name | Type | Description |
|---|---|---|
| id | [ItemID](../cache/itemid.md?sid=flytestdlib_cache_itemid) | The unique identifier of the item to retrieve. |
Returns
| Type | Description |
|---|---|
([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](../cache/itemid.md?sid=flytestdlib_cache_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
| Name | Type | Description |
|---|---|---|
| id | [ItemID](../cache/itemid.md?sid=flytestdlib_cache_itemid) | The 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
| Type | Description |
|---|---|
([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](../cache/itemid.md?sid=flytestdlib_cache_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
| Name | Type | Description |
|---|---|---|
| id | [ItemID](../cache/itemid.md?sid=flytestdlib_cache_itemid) | The unique identifier of the item to mark for delayed deletion. |
Returns
| Type | Description |
|---|---|
error | An error if the item cannot be queued for deletion. |