module

CrystalScript::DB

Constants

CREATE_CACHE_ENTRIES_SQL = " CREATE TABLE IF NOT EXISTS cache_entries (\n id INTEGER PRIMARY KEY,\n content_hash TEXT NOT NULL,\n source_path TEXT NOT NULL,\n compiler_version TEXT NOT NULL,\n compile_flags TEXT NOT NULL DEFAULT '',\n created_at INTEGER NOT NULL,\n last_accessed INTEGER NOT NULL,\n size_bytes INTEGER NOT NULL,\n UNIQUE(source_path)\n )"
CREATE_INDEX_CONTENT_HASH_SQL = " CREATE INDEX IF NOT EXISTS idx_content_hash ON cache_entries(content_hash)"
CREATE_INDEX_LOOKUP_SQL = " CREATE INDEX IF NOT EXISTS idx_lookup ON cache_entries(source_path, content_hash, compile_flags)"
CREATE_INDEX_LRU_SQL = " CREATE INDEX IF NOT EXISTS idx_lru ON cache_entries(last_accessed)"
CREATE_INDEX_SOURCE_PATH_SQL = " CREATE INDEX IF NOT EXISTS idx_source_path ON cache_entries(source_path)"
CREATE_SCHEMA_VERSION_SQL = " CREATE TABLE IF NOT EXISTS schema_version (\n version INTEGER PRIMARY KEY\n )"
SCHEMA_VERSION = 1

Instance methods

add_entry(db : ::DB::Database, content_hash : String, source_path : String, compiler_version : String, compile_flags : String, size_bytes : Int64) : Int64

Add new cache entry

count_entries_with_content_hash(db : ::DB::Database, content_hash)
delete_all_entries(db : ::DB::Database)

Delete all entries (also deletes all binary files)

delete_entry(db : ::DB::Database, entry : CacheEntry)

Delete a specific entry by id (also deletes the binary file)

get_all_entries(db : ::DB::Database) : Array(CacheEntry)

Get all cache entries

get_entry(db : ::DB::Database, content_hash : String, source_path : String, compile_flags : String) : CacheEntry | Nil

Get cached entry by source path, content hash, and compile flags

get_entry_by_source(db : ::DB::Database, source_path : String) : CacheEntry | Nil

Get entry for a specific source path (returns single entry since source_path is unique)

get_stats(db : ::DB::Database) : CacheStats

Get cache statistics Counts all entries but sums only unique binary sizes (entries can share binaries via content_hash)

init(db : ::DB::Database)
update_accessed(db : ::DB::Database, entry_id : Int64)

Update last_accessed timestamp for an entry

upsert_entry(db : ::DB::Database, content_hash : String, source_path : String, compiler_version : String, compile_flags : String, size_bytes : Int64) : String | Nil

Upsert cache entry - inserts new or updates existing entry for source_path Returns the old content_hash if an entry was updated, nil if inserted

validate_schema(db : ::DB::Database, db_path : Path)
with_db

Nested types