cache
Cache management for compiled solvers.
This module provides utilities for managing the cache directory where compiled JAX solvers are stored. The cache location follows platform conventions:
- Linux:
~/.cache/openscvx/ - macOS:
~/Library/Caches/openscvx/ - Windows:
%LOCALAPPDATA%/openscvx/Cache/
The cache location can be overridden by setting the OPENSCVX_CACHE_DIR
environment variable.
Example
Get the cache directory::
import openscvx as ox
print(ox.get_cache_dir()) # /home/user/.cache/openscvx
Clear all cached solvers::
import openscvx as ox
ox.clear_cache()
Check cache size::
import openscvx as ox
size_mb = ox.get_cache_size() / (1024 * 1024)
print(f"Cache size: {size_mb:.1f} MB")
clear_cache() -> int
¶
Clear all cached compiled solvers.
Removes all files in the cache directory. The directory itself is preserved but emptied.
Returns:
| Type | Description |
|---|---|
int
|
Number of files deleted |
Example
Clear the cache::
import openscvx as ox
deleted = ox.clear_cache()
print(f"Deleted {deleted} cached files")
Source code in openscvx/utils/cache.py
get_cache_dir() -> Path
¶
Get the cache directory for compiled solvers.
The cache location is determined in the following order:
1. OPENSCVX_CACHE_DIR environment variable (if set)
2. Platform-specific default:
- Linux: ~/.cache/openscvx/
- macOS: ~/Library/Caches/openscvx/
- Windows: %LOCALAPPDATA%/openscvx/Cache/
Returns:
| Type | Description |
|---|---|
Path
|
Path to the cache directory (may not exist yet) |
Source code in openscvx/utils/cache.py
get_cache_size() -> int
¶
Get the total size of the cache in bytes.
Returns:
| Type | Description |
|---|---|
int
|
Total size of all files in the cache directory in bytes. |
int
|
Returns 0 if the cache directory doesn't exist. |
Example
Check cache size in megabytes::
import openscvx as ox
size_mb = ox.get_cache_size() / (1024 * 1024)
print(f"Cache size: {size_mb:.1f} MB")