tenets.storage
Package¶
Storage module for persistence and caching.
This module handles all storage needs including: - File analysis caching - Tenet/session persistence - Configuration/state storage
Classes¶
AnalysisCache¶
Specialized cache for file analysis results.
Initialize analysis cache.
PARAMETER | DESCRIPTION |
---|---|
cache_dir | Directory for cache storage TYPE: |
Attributes¶
cache_dirinstance-attribute
¶
memoryinstance-attribute
¶
diskinstance-attribute
¶
loggerinstance-attribute
¶
Functions¶
get_file_analysis¶
Get cached analysis for a file.
PARAMETER | DESCRIPTION |
---|---|
file_path | Path to the file TYPE: |
RETURNS | DESCRIPTION |
---|---|
Optional[FileAnalysis] | Cached FileAnalysis or None |
put_file_analysis¶
Cache file analysis.
PARAMETER | DESCRIPTION |
---|---|
file_path | Path to the file TYPE: |
analysis | Analysis to cache TYPE: |
CacheManager¶
Manages all caching operations.
Initialize cache manager.
PARAMETER | DESCRIPTION |
---|---|
config | Tenets configuration TYPE: |
Attributes¶
configinstance-attribute
¶
cache_dirinstance-attribute
¶
loggerinstance-attribute
¶
analysisinstance-attribute
¶
generalinstance-attribute
¶
memoryinstance-attribute
¶
Functions¶
get_or_compute¶
get_or_compute(key: str, compute_fn: Callable[[], T], ttl: Optional[int] = None, use_memory: bool = True) -> T
SessionDB¶
SQLite-backed session storage.
Manages two tables
- sessions(id, name, created_at, metadata)
- session_context(id, session_id, kind, content, created_at)
class explicitly removes child rows where appropriate.
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
dbinstance-attribute
¶
Functions¶
create_session¶
get_session¶
list_sessions¶
get_active_session¶
Return the currently active session, if any.
Chooses the most recently created active session if multiple are marked active.
add_context¶
delete_session¶
Delete a session record by name.
This removes the session row and, by default, all related entries from session_context
.
PARAMETER | DESCRIPTION |
---|---|
name | Session name to delete. TYPE: |
purge_context | When True (default), also remove all associated rows from TYPE: |
RETURNS | DESCRIPTION |
---|---|
bool | True if a session row was deleted; False if no session matched. |
delete_all_sessions¶
Delete all sessions. Returns the number of sessions removed.
If purge_context is True, also clears all session_context rows.
update_session_metadata¶
Merge updates
into the session's metadata JSON.
Returns True if the session exists and was updated.
set_active¶
Mark a session as active/inactive via metadata.
When activating a session, all other sessions are marked inactive to guarantee there is at most one active session at a time.
Database¶
SQLitePathsdataclass
¶
Modules¶
cache
- Cache modulesession_db
- Session Db modulesqlite
- Sqlite module