ThreatFlux Cache
An async, typed cache for Rust applications that need pluggable storage, bounded key histories, metadata, and simple entry queries.
ThreatFlux Cache keeps its working set in memory. Applications can use the
built-in memory backend, enable filesystem snapshots, or implement
StorageBackend for another persistence mechanism.
Highlights
- Generic, serializable keys, values, and metadata
putsemantics for one current value per keyadd_entrysemantics for bounded per-key history- LRU, LFU, FIFO, TTL, and manual eviction strategies
- Timestamp, access-count, key-pattern, and metadata-category filters
- Bounded, versioned JSON filesystem snapshots
- An async API built on Tokio with no unsafe code in the crate
Install
The default features enable the filesystem backend and JSON serialization. The
default cache type still uses the in-memory backend unless you construct a
FilesystemBackend explicitly.
[]
= "0.2.0"
= { = "1", = ["derive"] }
= { = "1", = ["macros", "rt-multi-thread"] }
For a memory-only build:
[]
= { = "0.2.0", = false }
= { = "1", = ["derive"] }
= { = "1", = ["macros", "rt-multi-thread"] }
ThreatFlux Cache requires Rust 1.95.0 or newer.
Quick start
use ;
use ;
async
put replaces the history for its key. Use CacheEntry and add_entry when
you want to retain multiple versions:
use ;
# async
See examples/basic_usage.rs and
examples/custom_entry.rs for complete programs.
Filesystem snapshots
Filesystem persistence requires the filesystem-backend feature. The backend
path is authoritative; configure persistence separately so the cache loads and
saves snapshots.
use ;
# async
flush waits for the backend to finish writing the current state. Snapshots are
not a transactional database or substitute for a system of record. Read
docs/PERSISTENCE.md before relying on restart recovery
or sharing a directory between processes.
Feature flags
| Feature | Default | Surface enabled |
|---|---|---|
filesystem-backend |
yes | FilesystemBackend; also enables Tokio filesystem I/O and JSON serialization |
full |
no | Alias for every supported optional feature |
For tested feature combinations and current limitations, see
docs/FEATURES.md.
Behavioral boundaries
getreturns the newest entry and records an access;get_entriesrecords an access for every returned version.- Search patterns are case-sensitive substrings of the key's
Displayoutput; values are not full-text searched. get,get_entries,contains,len, and search exclude expired entries; search can opt into expired results.- LRU, LFU, and FIFO eviction remove one entire key and its history when the global limit is crossed.
default_ttlapplies to entries that do not already have an explicit expiry.- Zero entry limits and a zero persistence sync interval are rejected; with
eviction disabled, an insertion that would grow a full cache returns
CapacityExceeded.
The complete contract is documented in
docs/BEHAVIOR.md. This crate is pre-1.0; minor releases may
refine APIs and on-disk representation.
Extending the cache
Implement StorageBackend
to provide a different snapshot store. Implement EntryMetadata to attach
domain-specific metadata and expose a category to the built-in search filters.
Development and security
CONTRIBUTING.md— contribution workflowDEVELOPMENT.md— local setup and commandsTESTING.md— validation matrixSECURITY.md— private vulnerability reportingCHANGELOG.md— release history
License
Licensed under the MIT License.