Skip to content

Graph Cache Manager

graph_cache_manager

Graph Cache Manager - Graph Caching Interface.

Provides manager interface compatible with PlotService for graph caching operations.

Classes:

Name Description
GraphCacheManager

Manager wrapper for GraphCache with metadata support

Classes

GraphCacheManager

GraphCacheManager(max_size: int = 100, default_ttl: int = 3600)

Manager for graph caching operations.

Wraps GraphCache with additional management capabilities and metadata support.

Attributes:

Name Type Description
cache GraphCache

Underlying cache instance

Methods:

Name Description
cache_graph

Cache a Plotly figure

get_cached_graph

Retrieve cached Plotly figure

clear

Clear all cached graphs

get_stats

Get cache statistics

Initialize graph cache manager.

Parameters:

Name Type Description Default
max_size int

Maximum number of graphs to cache.

100
default_ttl int

Default TTL in seconds (1 hour).

3600
Source code in src/infrastructure/cache/graph_cache_manager.py
def __init__(
    self,
    max_size: int = 100,
    default_ttl: int = 3600
):
    """
    Initialize graph cache manager.

    Parameters
    ----------
    max_size : int, default=100
        Maximum number of graphs to cache.
    default_ttl : int, default=3600
        Default TTL in seconds (1 hour).
    """
    self.cache = GraphCache(
        max_size=max_size,
        default_ttl=default_ttl
    )
    logger.info("GraphCacheManager initialized")
Functions
cache_graph
cache_graph(key: str, figure: Figure, metadata: Optional[dict] = None, ttl: Optional[int] = None) -> None

Cache a Plotly figure.

Parameters:

Name Type Description Default
key str

Cache key

required
figure Figure

Plotly figure to cache

required
metadata Optional[dict]

Optional metadata (for logging/tracking)

None
ttl Optional[int]

TTL in seconds (if None, uses default)

None
Source code in src/infrastructure/cache/graph_cache_manager.py
def cache_graph(
    self,
    key: str,
    figure: go.Figure,
    metadata: Optional[dict] = None,
    ttl: Optional[int] = None
) -> None:
    """
    Cache a Plotly figure.

    Parameters
    ----------
    key : str
        Cache key
    figure : go.Figure
        Plotly figure to cache
    metadata : Optional[dict], default=None
        Optional metadata (for logging/tracking)
    ttl : Optional[int], default=None
        TTL in seconds (if None, uses default)
    """
    self.cache.cache_figure(key, figure, ttl=ttl)

    if metadata:
        logger.debug(f"Cached graph with metadata: {metadata}")
get_cached_graph
get_cached_graph(key: str) -> Optional[go.Figure]

Retrieve cached Plotly figure.

Parameters:

Name Type Description Default
key str

Cache key

required

Returns:

Type Description
Optional[Figure]

Cached figure or None if not found

Source code in src/infrastructure/cache/graph_cache_manager.py
def get_cached_graph(self, key: str) -> Optional[go.Figure]:
    """
    Retrieve cached Plotly figure.

    Parameters
    ----------
    key : str
        Cache key

    Returns
    -------
    Optional[go.Figure]
        Cached figure or None if not found
    """
    return self.cache.get_cached_figure(key)
clear
clear() -> None

Clear all cached graphs.

Source code in src/infrastructure/cache/graph_cache_manager.py
def clear(self) -> None:
    """Clear all cached graphs."""
    self.cache.clear()
    logger.info("All cached graphs cleared")
get_stats
get_stats() -> dict

Get cache statistics.

Returns:

Type Description
dict

Statistics including size, max_size, etc.

Source code in src/infrastructure/cache/graph_cache_manager.py
def get_stats(self) -> dict:
    """
    Get cache statistics.

    Returns
    -------
    dict
        Statistics including size, max_size, etc.
    """
    return self.cache.get_stats()

Functions