5.2.3. ytpb.cache¶
Naive disk-based caching via JSON files.
The cache invalidation is based on the filenaming: <expires-at>~<key>.
In the playback context, key is a video ID and expires-at is a
timestamp referred to the expiration time of segment base URL.
- ytpb.cache.read_from_cache(key: str, cache_directory: Path) dict | None¶
Reads a cached item.
- Parameters:
key – A cached item key.
cache_directory – A cached items location.
- Returns:
A dictionary of a cached item.
- ytpb.cache.write_to_cache(key: str, expires_at: str, item: dict, cache_directory: Path) None¶
Writes a cache item to a file.
The existing cached items with
key(both expired and unexpired) will be removed before writing.- Parameters:
key – A cache item key.
expires_at – When a cache item will be expired.
cache_directory – A cached items location.