zooui.objects.mediaobjects.mediaobjectsutils.svg.svgcache.svgcache module

SVG cache management with hashed storage.

class zooui.objects.mediaobjects.mediaobjectsutils.svg.svgcache.svgcache.SVGCache(cache_root=None)[source]

Bases: object

Manages hashed SVG cache with svg_ prefix and flat directory structure.

Hash format: svg_{8_char_sha1} Directory: XDG cache dir / svg (flat, no subdirectories)

Initialize SVG cache.

Parameters:

cache_root – Root directory for cache (default: XDG cache dir / svg)

_compute_hash(svg_content)[source]

Compute 8-character SHA1 hash with svg_ prefix.

Parameters:

svg_content – SVG XML content as UTF-8 string

Returns:

svg_{8_char_hex}

Return type:

Hash in format

store_svg(svg_content, max_retries=3)[source]

Store SVG content in cache with retry logic on write failure.

Parameters:
  • svg_content – SVG XML content as UTF-8 string

  • max_retries – Maximum number of retry attempts (default: 3)

Returns:

Cache hash (svg_{8_char_hex})

Raises:
  • ValueError – If svg_content is empty or invalid

  • Exception – If cache write fails after all retry attempts

get_cache_path(content_hash)[source]

Get file path for given cache hash.

Parameters:

content_hash – Cache hash in format svg_{8_char_hex}

Returns:

Path to cached SVG file

has_hash(content_hash)[source]

Check if hash exists in cache.

Parameters:

content_hash – Cache hash to check

Returns:

True if hash exists in cache

get_svg_content(content_hash)[source]

Get SVG content from cache.

Parameters:

content_hash – Cache hash to retrieve

Returns:

SVG content as string, or None if not found

cleanup_old_files(max_age_days=14)[source]

Remove cache files older than specified days.

Parameters:

max_age_days – Maximum age in days (default: 14)

Returns:

Tuple of (files_removed, bytes_freed)

cleanup_on_exit()[source]

Perform cleanup on program exit.

Currently removes all cache files. Could be modified to keep recent files if needed.

get_cache_stats()[source]

Get cache statistics.

Returns:

Dictionary with cache statistics

zooui.objects.mediaobjects.mediaobjectsutils.svg.svgcache.svgcache.get_svg_cache()[source]

Get global SVG cache instance (singleton pattern).

Returns:

Global SVGCache instance

zooui.objects.mediaobjects.mediaobjectsutils.svg.svgcache.svgcache.compute_svg_hash(svg_content)[source]

Compute SVG hash without storing in cache.

Parameters:

svg_content – SVG XML content as UTF-8 string

Returns:

svg_{8_char_hex}

Return type:

Hash in format

See Also

  • zooui/objects/mediaobjects/svgmediaobject - SVGMediaObject class

  • zooui/objects/mediaobjects/mediaobjectsutils/svg/utils/svgarrowutils - SVG arrow utilities

  • zooui/objects/mediaobjects/mediaobjectsutils/svg/utils/svgcircleutils - SVG circle utilities

  • zooui/objects/mediaobjects/mediaobjectsutils/svg/utils/svgsquareutils - SVG square utilities

  • zooui/objects/mediaobjects/mediaobjectsutils/svg/utils/svgtriangleutils - SVG triangle utilities