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
| Name | Type | Description |
|---|---|---|
| ctx | context.Context | The 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
| Name | Type | Description |
|---|---|---|
| id | string | The unique identifier of the cache item to retrieve. |
Returns
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
([CacheItem](cacheitem.md?sid=flytestdlib_utils_cacheitem), error) | The existing or newly created CacheItem, and an error if the operation failed. |