Cache
cache
¶
Classes:
| Name | Description |
|---|---|
Cache |
Caching module prefetches segments of data that has long IO, for more responsive experience. |
DataRequest |
Object wrapping user's element of interest into a fetch request. |
Cache
¶
Caching module prefetches segments of data that has long IO, for more responsive experience.
Methods:
| Name | Description |
|---|---|
__init__ |
Constructor of the Cache component for long IO prefetching to mask latency behind wide bandwidth. |
get_data |
Request data from the cache. |
join |
Wait on the background cache management thread. |
start |
Start the background cache management thread. |
__init__
¶
__init__(fetch_fn: Callable[[Any], Dict[Any, Any]], fetch_offset: int)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Callable[[Any], Dict[Any, Any]]
|
User-provided function with long IO to use for asynchronous prefetching (database operation, API call, FFmpeg decoding, etc.). |
required |
|
int
|
How many elements before the requested to cache in case of jumping backwards during playback. |
required |
_fetch
¶
Fetches data from an external source using user-defined IO function.
Returns:
| Type | Description |
|---|---|
Dict[Any, Any]
|
Dict[Any, Any]: Mapping from a unique key to the element of interest. |
_process_request
¶
_process_request(request: DataRequest)
Process user request for the next element of interest.
Runs user-provided long-IO fetch procedure if the data is not immediately available in cache or isn't already being fetched. Updates the cache and notifies all watchers waiting for this element.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
DataRequest
|
User-requested element of interest. |
required |
_run_cache_manager
¶
Main loop of the background continuous cache management thread.
Processes requests from the user and prefetches most likely used next segment of elements.
get_data
¶
get_data(key: Any) -> Any
Request data from the cache.
Checks if data is already in the cache. Adds a request to the queue for background processing. Returns immediately if requested data is cached, otherwise waits for the background task to fetch it. Stalls until the data is available in the cache for the given key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Unique key correctly identifying the element of interest in the user-provided fetch function. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The requested element of interest. |
DataRequest
dataclass
¶
Object wrapping user's element of interest into a fetch request.