Nasty.Statistics.Neural.Transformers.CacheManager (Nasty v0.3.0)
View SourceManages caching of downloaded transformer models.
Handles model versioning, disk space management, and cache lookup to avoid re-downloading large models from HuggingFace Hub.
Summary
Functions
Calculates total cache size in bytes.
Clears cached models.
Gets the cached model path if it exists.
Lists all cached models with their metadata.
Records a model in the cache registry.
Types
@type cache_entry() :: %{ model_name: atom(), path: String.t(), size_bytes: integer(), downloaded_at: DateTime.t(), version: String.t() }
Functions
Calculates total cache size in bytes.
Examples
{:ok, size} = CacheManager.cache_size(cache_dir)
# => {:ok, 1_234_567_890}
Clears cached models.
Examples
# Clear specific model
CacheManager.clear_cache(:roberta_base, cache_dir)
# Clear all models
CacheManager.clear_cache(:all, cache_dir)
Gets the cached model path if it exists.
Examples
CacheManager.get_cached_model(:roberta_base, "/path/to/cache")
# => {:ok, "/path/to/cache/roberta-base"}
# or :not_found
@spec list_cached_models(String.t()) :: [cache_entry()]
Lists all cached models with their metadata.
Examples
CacheManager.list_cached_models(cache_dir)
# => [%{model_name: :roberta_base, size_bytes: 500_000_000, ...}, ...]
Records a model in the cache registry.
Examples
CacheManager.register_cached_model(:roberta_base, "/path/to/cache")