Skip to main content

CacheConfig

Struct CacheConfig 

Source
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

  • enabled now defaults to false (was true)
  • with_max_entries() and with_ttl() also set enabled: false
  • New enabled() constructor for explicit opt-in

See module documentation for detailed guidance.

Fields§

§enabled: bool

Enable 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: usize

Maximum 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: u64

Time-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: bool

Whether 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

Source

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 default
Source

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 default
Source

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);
Source

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);
Source

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

Source§

fn clone(&self) -> CacheConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CacheConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CacheConfig

Source§

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)
Source§

impl<'de> Deserialize<'de> for CacheConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CacheConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for CacheConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,