pub struct CacheConfig {
pub enabled: bool,
pub max_entries: usize,
pub ttl_seconds: u64,
pub cache_list_queries: bool,
}Expand description
Cache configuration - disabled by default as of v2.0.0-rc.12.
FraiseQL’s architecture (precomputed views + optimized PostgreSQL) makes caching unnecessary for most use cases. Enable only for federation or expensive computations.
§Key Changes in rc.12
enablednow defaults tofalse(wastrue)with_max_entries()andwith_ttl()also setenabled: false- New
enabled()constructor for explicit opt-in
See module documentation for detailed guidance.
Fields§
§enabled: boolEnable response caching.
Default: false (changed from true in v2.0.0-rc.12)
Enable only for:
- Federation with slow external services
- Expensive computations not covered by precomputed views
- High-frequency repeated queries with identical parameters
See Issue #40 for performance analysis.
max_entries: usizeMaximum number of cached entries.
When this limit is reached, the least-recently-used (LRU) entry is evicted to make room for new entries. This hard limit prevents unbounded memory growth.
Recommended values:
- Development: 1,000
- Production (small): 10,000
- Production (large): 50,000
Default: 10,000 entries (~100 MB estimated memory)
ttl_seconds: u64Time-to-live (TTL) in seconds for cached entries.
Entries older than this are considered expired and will be removed on next access. This acts as a safety net for cases where invalidation might be missed (e.g., database changes outside of mutations).
Recommended values:
- Development: 3,600 (1 hour)
- Production: 86,400 (24 hours)
- Long-lived data: 604,800 (7 days)
Default: 86,400 seconds (24 hours)
cache_list_queries: boolWhether to cache list queries.
List queries (e.g., users(limit: 100)) can have large result sets that
consume significant memory. Set to false to only cache single-object queries.
Note: Currently not implemented (all queries are cached). This field is reserved for future use.
Default: true
Implementations§
Source§impl CacheConfig
impl CacheConfig
Sourcepub const fn with_max_entries(max_entries: usize) -> Self
pub const fn with_max_entries(max_entries: usize) -> Self
Create cache configuration with custom max entries.
Uses default values for other fields (enabled=false, 24h TTL).
§Arguments
max_entries- Maximum number of entries in cache
§Example
use fraiseql_core::cache::CacheConfig;
let config = CacheConfig::with_max_entries(50_000);
assert_eq!(config.max_entries, 50_000);
assert!(!config.enabled); // Disabled by defaultSourcepub const fn with_ttl(ttl_seconds: u64) -> Self
pub const fn with_ttl(ttl_seconds: u64) -> Self
Create cache configuration with custom TTL.
Uses default values for other fields (enabled=false, 10,000 entries).
§Arguments
ttl_seconds- Time-to-live in seconds
§Example
use fraiseql_core::cache::CacheConfig;
let config = CacheConfig::with_ttl(3_600); // 1 hour
assert_eq!(config.ttl_seconds, 3_600);
assert!(!config.enabled); // Disabled by defaultSourcepub const fn enabled() -> Self
pub const fn enabled() -> Self
Create cache configuration with caching enabled.
Use this method when you explicitly need caching (e.g., federation, expensive computations). Most FraiseQL deployments don’t need this.
§Example
use fraiseql_core::cache::CacheConfig;
let config = CacheConfig::enabled();
assert!(config.enabled);
assert_eq!(config.max_entries, 10_000);Sourcepub const fn disabled() -> Self
pub const fn disabled() -> Self
Create cache configuration with caching disabled.
This is now the default behavior. Use this method for explicit clarity or to override a previously enabled configuration.
§Example
use fraiseql_core::cache::CacheConfig;
let config = CacheConfig::disabled();
assert!(!config.enabled);Sourcepub const fn estimated_memory_bytes(&self) -> usize
pub const fn estimated_memory_bytes(&self) -> usize
Estimate memory usage in bytes for this configuration.
This is a rough estimate assuming average entry size of 10 KB. Actual memory usage will vary based on query result sizes.
§Returns
Estimated memory usage in bytes
§Example
use fraiseql_core::cache::CacheConfig;
let config = CacheConfig::default();
let estimated_bytes = config.estimated_memory_bytes();
println!("Estimated memory: {} MB", estimated_bytes / 1_000_000);Trait Implementations§
Source§impl Clone for CacheConfig
impl Clone for CacheConfig
Source§fn clone(&self) -> CacheConfig
fn clone(&self) -> CacheConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for CacheConfig
impl Debug for CacheConfig
Source§impl Default for CacheConfig
impl Default for CacheConfig
Source§fn default() -> Self
fn default() -> Self
Default cache configuration - DISABLED by default as of v2.0.0-rc.12.
FraiseQL uses precomputed views (tv_* tables) and optimized PostgreSQL queries that are typically faster than cache overhead for most use cases.
Enable caching ONLY if you have:
- Federation with slow external services
- Expensive computations not covered by precomputed views
- High-frequency repeated queries (>1000 QPS with same params)
See Issue #40 for performance analysis.
§Current Default
- Caching: DISABLED
- 10,000 max entries (~100 MB if enabled)
- 24 hour TTL
- List queries cached (when enabled)