Cache Module

Cache management for card data and images.

class simulchip.cache.CacheManager[source]

Bases: object

Manages caching of card data and images.

__init__(cache_dir=None)[source]

Initialize cache manager.

Parameters:

cache_dir (Optional[Path]) – Directory for cache storage (defaults to .cache)

get_cached_cards()[source]

Get cached card data.

Return type:

Optional[Dict[str, Any]]

Returns:

Dictionary of card data or None if not cached

cache_cards(cards_data)[source]

Cache card data.

Parameters:

cards_data (Dict[str, Any]) – Card data to cache

Return type:

None

get_cached_packs()[source]

Get cached pack data.

Return type:

Optional[List[Dict[str, Any]]]

Returns:

List of pack data or None if not cached

cache_packs(packs_data)[source]

Cache pack data.

Parameters:

packs_data (List[Dict[str, Any]]) – Pack data to cache

Return type:

None

get_card_image_path(card_code, extension='png')[source]

Get path for cached card image.

Parameters:
  • card_code (str) – Card code

  • extension (str) – File extension

Return type:

Path

Returns:

Path to image file

has_card_image(card_code)[source]

Check if card image is cached.

Parameters:

card_code (str) – Card code

Return type:

bool

Returns:

True if image is cached

get_card_image(card_code)[source]

Get cached card image.

Parameters:

card_code (str) – Card code

Return type:

Optional[Image]

Returns:

PIL Image or None if not cached

download_and_cache_image(card_code, image_url)[source]

Download and cache card image.

Parameters:
  • card_code (str) – Card code

  • image_url (str) – URL to download image from

Return type:

Optional[Image]

Returns:

PIL Image or None if download fails

clear_cache()[source]

Clear all cached data.

Return type:

None

get_cache_stats()[source]

Get cache statistics.

Return type:

Dict[str, Any]

Returns:

Dictionary with cache stats

get_cache_metadata()[source]

Get cache metadata including timestamps and pack info.

Return type:

Dict[str, Any]

Returns:

Dictionary with cache metadata or empty dict if not exists

update_cache_metadata(metadata)[source]

Update cache metadata.

Parameters:

metadata (Dict[str, Any]) – Metadata dictionary to save

Return type:

None

get_latest_pack_date(packs)[source]

Get the release date of the most recent pack.

Parameters:

packs (List[Dict[str, Any]]) – List of pack data

Return type:

Optional[str]

Returns:

Latest release date string or None

is_cache_valid(packs=None)[source]

Check if cache is still valid based on pack releases.

Parameters:

packs (Optional[List[Dict[str, Any]]]) – Optional pack data to check against

Return type:

bool

Returns:

True if cache is valid, False if it needs refresh

mark_cache_fresh(packs)[source]

Mark cache as freshly updated with pack info.

Parameters:

packs (List[Any]) – Current pack data

Return type:

None