ontocast cache commands for inspecting and trimming the on-disk cache.
The cache bounds itself automatically (see
:meth:~ontocast.tool.cache.Cacher.prune); these commands exist for the cases
automation deliberately stays out of: inspecting what is stored, forcing a trim
with a different ceiling, and clearing directories left behind by an older cache
layout.
cache()
Inspect and trim the OntoCast on-disk cache.
Source code in ontocast/cli/cache.py
| @click.group("cache")
def cache() -> None:
"""Inspect and trim the OntoCast on-disk cache."""
|
clear(subdir)
Delete cached entries.
Source code in ontocast/cli/cache.py
| @cache.command("clear")
@click.option(
"--subdir",
default=None,
help="Clear only this tool's cache (e.g. llm). Omit to clear everything.",
)
@click.confirmation_option(prompt="Delete cached entries?")
def clear(subdir: str | None) -> None:
"""Delete cached entries."""
cacher = _build_cacher()
before = cacher.cache_stats().total_size_bytes
cacher.clear(subdirectory=subdir)
after = cacher.cache_stats().total_size_bytes
target = subdir or "all subdirectories"
click.echo(f"Cleared {target}; freed {_format_bytes(before - after)}.")
|
prune(max_bytes, ttl_days, orphaned)
Trim the cache by size and age, or clear orphaned subdirectories.
Source code in ontocast/cli/cache.py
| @cache.command("prune")
@click.option(
"--max-bytes",
type=int,
default=None,
help="Size ceiling in bytes. Defaults to ONTOCAST_CACHE_MAX_BYTES.",
)
@click.option(
"--ttl-days",
type=int,
default=None,
help="Drop entries unused for this many days.",
)
@click.option(
"--orphaned",
is_flag=True,
help="Instead of trimming by size, remove subdirectories no current tool writes to.",
)
def prune(max_bytes: int | None, ttl_days: int | None, orphaned: bool) -> None:
"""Trim the cache by size and age, or clear orphaned subdirectories."""
cacher = _build_cacher()
if orphaned:
_echo_report(cacher.prune_orphaned_subdirs(KNOWN_CACHE_SUBDIRS))
return
config_paths = Config().get_tool_config().path_config
_echo_report(
cacher.prune(
max_bytes=(
config_paths.cache_max_bytes if max_bytes is None else max_bytes
),
ttl_days=(config_paths.cache_ttl_days if ttl_days is None else ttl_days),
)
)
|
stats()
Show cache size, broken down by tool.
Source code in ontocast/cli/cache.py
| @cache.command("stats")
def stats() -> None:
"""Show cache size, broken down by tool."""
cacher = _build_cacher()
summary = cacher.cache_stats()
click.echo(f"Cache directory: {cacher.cache_dir}")
click.echo(
f"Total: {summary.total_files} entries, "
f"{_format_bytes(summary.total_size_bytes)}"
)
for name in sorted(summary.subdirectories):
entry = summary.subdirectories[name]
marker = "" if name in KNOWN_CACHE_SUBDIRS else " (orphaned)"
click.echo(
f" {name}: {entry.files} entries, "
f"{_format_bytes(entry.size_bytes)}{marker}"
)
|