Graph Cache¶
graph_cache ¶
Graph Cache - Plotly Figure Caching.
Provides specialized caching for Plotly graph objects with JSON serialization for efficient storage.
Classes:
| Name | Description |
|---|---|
GraphCache | Specialized cache for Plotly figures with JSON serialization |
Classes¶
GraphCache ¶
Bases: MemoryCache
Specialized cache for Plotly graph objects.
Provides JSON serialization for Plotly figures, graph-specific hash generation, and efficient storage of figure configurations.
Attributes:
| Name | Type | Description |
|---|---|---|
max_size | int | Maximum number of graphs to cache |
default_ttl | int | Default TTL in seconds |
Initialize graph cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_size | int | Maximum number of figures to cache. | 100 |
default_ttl | int | Default TTL in seconds (30 minutes). | 1800 |
Source code in src/infrastructure/cache/graph_cache.py
Functions¶
cache_figure ¶
Cache a Plotly figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Cache key | required |
figure | Figure | Plotly figure to cache | required |
ttl | Optional[int] | TTL in seconds | None |
Source code in src/infrastructure/cache/graph_cache.py
get_cached_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.py
generate_figure_key ¶
Generate unique cache key for figure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analysis_id | str | Analysis ID (e.g., 'UC1_1') | required |
filter_values | dict | Filter values used to generate figure | required |
config | Optional[dict] | Additional configuration parameters | None |
Returns:
| Type | Description |
|---|---|
str | Cache key |
Source code in src/infrastructure/cache/graph_cache.py
get ¶
Get value from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Cache key | required |
Returns:
| Type | Description |
|---|---|
Optional[Any] | Cached value or None if not found/expired |
Source code in src/infrastructure/cache/memory_cache.py
set ¶
Set value in cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Cache key | required |
value | Any | Value to cache | required |
ttl | Optional[int] | TTL in seconds (if None, uses default_ttl) | None |
Source code in src/infrastructure/cache/memory_cache.py
delete ¶
Delete entry from cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Cache key | required |
Returns:
| Type | Description |
|---|---|
bool | True if deleted, False if key not found |
Source code in src/infrastructure/cache/memory_cache.py
clear ¶
Clear all cache entries.
Source code in src/infrastructure/cache/memory_cache.py
exists ¶
Check if key exists in cache (and not expired).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Cache key | required |
Returns:
| Type | Description |
|---|---|
bool | True if exists and not expired |
Source code in src/infrastructure/cache/memory_cache.py
size ¶
Get current cache size.
Returns:
| Type | Description |
|---|---|
int | Number of entries in cache |
get_stats ¶
Get cache statistics.
Returns:
| Type | Description |
|---|---|
dict | Statistics including size, max_size, usage percentage |