class

Crinit::CacheStore

Inherits Reference < Object

Manages content-addressed local caching for remote assets based on SHA-256 digests.

Constants

SHA256_PATTERN = /\A[0-9a-fA-F]{64}\z/

Constructors

from_config(config : Config) : CacheStore
Source
new(custom_dir : Path | Nil = nil)
Source

Class methods

default_base_cache_dir
Source
digest(data : Bytes | String) : String

Computes SHA-256 hex digest for binary or string data.

Source
digest_file(path : Path) : String

Computes SHA-256 hex digest for an existing file.

Source
valid_sha256?(sha256 : String) : Bool

Validates whether a string matches standard 64-character hexadecimal SHA-256 formatting.

Source
validate_sha256!(sha256 : String) : Nil

Enforces SHA-256 format, raising SecurityError on invalid or traversing strings.

Source

Instance methods

cache_dir
Source
cache_file(sha256 : String) : Path
Source
get(sha256 : String) : Path | Nil

Retrieves the path to the cached asset, or nil if absent or corrupted.

Source
has?(sha256 : String) : Bool

Checks whether an asset with the given SHA-256 is present and uncorrupted in the cache.

Source
store(sha256 : String, data : Bytes | String) : Path

Atomically stores content in cache indexed by SHA-256 digest.

Source