grafos_cache/lib.rs
1//! Elastic sharded maps and TTL-driven object caches for grafOS.
2//!
3//! This crate provides two cache building blocks:
4//!
5//! - [`elastic::ElasticShardSet`] — a set of shards (each backed by a
6//! [`MemLease`](grafos_std::mem::MemLease) +
7//! [`FabricHashMap`](grafos_collections::map::FabricHashMap)) that can grow
8//! and shrink at runtime.
9//! - [`ttl::TtlObjectCache`] — an in-memory object cache with per-entry TTL and
10//! poll-driven expiry pruning.
11//!
12//! # Quick start
13//!
14//! ```rust
15//! use grafos_cache::elastic::ElasticShardSet;
16//! use grafos_cache::ttl::{TtlObjectCache, CacheStats};
17//! use grafos_leasekit::RenewalPolicy;
18//!
19//! # grafos_std::host::reset_mock();
20//! # grafos_std::host::mock_set_fbmu_arena_size(65536);
21//! // Elastic shard set
22//! let mut shards: ElasticShardSet<u32, u32> =
23//! ElasticShardSet::new(2, 64, 8, 8)?;
24//! shards.put(&1, &100)?;
25//! assert_eq!(shards.get(&1)?, Some(100));
26//!
27//! // TTL object cache
28//! let mut cache = TtlObjectCache::<String>::new(RenewalPolicy::default());
29//! # Ok::<(), grafos_std::FabricError>(())
30//! ```
31//!
32//! # Feature flags
33//!
34//! | Feature | Default | Effect |
35//! |---------|---------|--------|
36//! | `std` | Yes | Enables `std` in grafos-std (thread-local mock state) |
37//! | `observe` | No | Optional grafos-observe integration |
38
39#![cfg_attr(not(feature = "std"), no_std)]
40
41extern crate alloc;
42
43pub mod elastic;
44pub mod ttl;