Skip to main content

CacheConfig

Struct CacheConfig 

Source
pub struct CacheConfig {
Show 21 fields pub group_cache: CacheEntryConfig, pub device_registry_cache: CacheEntryConfig, pub lid_pn_cache: CacheEntryConfig, pub recent_messages: CacheEntryConfig, pub message_retry_counts: CacheEntryConfig, pub undecryptable_dispatched: CacheEntryConfig, pub pdo_pending_requests: CacheEntryConfig, pub pdo_requested: CacheEntryConfig, pub sender_key_devices_cache: CacheEntryConfig, pub session_recreate_history: CacheEntryConfig, pub session_locks_capacity: u64, pub chat_lanes_capacity: u64, pub group_distribution_locks_capacity: u64, pub resend_rate_limiter_capacity: u64, pub sent_message_ttl_secs: u64, pub msg_secret_policy: MsgSecretPolicy, pub msg_secret_retention: MsgSecretRetention, pub seed_msg_secrets_from_history: bool, pub original_message_resolver: Option<Arc<dyn OriginalMessageResolver>>, pub msg_secret_resolver_timeout: Duration, pub cache_stores: CacheStores,
}
Expand description

Configuration for all client caches and resource pools.

All fields default to WhatsApp Web behavior. Use ..Default::default() to override only specific settings.

§Example — tune TTL/capacity

use whatsapp_rust::{CacheConfig, CacheEntryConfig};
use std::time::Duration;

let config = CacheConfig {
    group_cache: CacheEntryConfig::new(None, 1_000), // no TTL
    ..Default::default()
};

§Example — Redis for group and device registry caches

use std::sync::Arc;
use whatsapp_rust::{CacheConfig, CacheStores};

let redis = Arc::new(MyRedisCacheStore::new("redis://localhost:6379"));
let config = CacheConfig {
    cache_stores: CacheStores {
        group_cache: Some(redis.clone()),
        device_registry_cache: Some(redis.clone()),
        ..Default::default()
    },
    ..Default::default()
};

Fields§

§group_cache: CacheEntryConfig

Group metadata cache (time_to_live). Default: 1h TTL, 250 entries.

§device_registry_cache: CacheEntryConfig

Device registry cache (time_to_live). Default: 1h TTL, 5000 entries (holds a large group’s per-member device set; a near-max group is ~1024).

§lid_pn_cache: CacheEntryConfig

LID-to-phone cache. WAWebLidPnCache uses plain Maps with no expiry and no size cap; evicting a still-valid mapping silently downgrades Signal addresses to @c.us. Default: no timeout, capacity u64::MAX (effectively unbounded — the cache has no dedicated unbounded() builder).

§recent_messages: CacheEntryConfig

Optional L1 in-memory cache for sent messages (retry support). Default: capacity 0 (disabled — DB-only, matching WA Web). Set capacity > 0 to enable a fast in-memory cache in front of the DB.

§message_retry_counts: CacheEntryConfig

Message retry counts (time_to_live). Default: 1h TTL, 500 entries. Long enough that the MAX_DECRYPT_RETRIES cap survives spaced redeliveries.

§undecryptable_dispatched: CacheEntryConfig

Dedup key for UndecryptableMessage dispatch so a server resend of the same id does not surface a second notification. Default: 5m TTL, 1000 entries.

§pdo_pending_requests: CacheEntryConfig

PDO pending requests (time_to_live). Default: 30s TTL, 200 entries.

§pdo_requested: CacheEntryConfig

Messages already covered by a placeholder-resend PDO request (time_to_live). WA Web keeps a session-lifetime set (WAWebNonMessageDataRequestPlaceholderMessageResendUtils) so each message triggers at most one request; without it, every redelivery of an undecryptable message re-asks the phone (a stuck sender resending every ~11s produced ~700 requests in 3h). The TTL stands in for “session lifetime” with bounded memory. Default: 24h TTL, 512 entries.

§sender_key_devices_cache: CacheEntryConfig

Sender key device tracking cache (time_to_idle). Default: 1h TTI, 500 entries. Caches per-group SKDM distribution state to avoid DB reads on every group send.

§session_recreate_history: CacheEntryConfig

Session-recreate throttle history (time_to_live). Default: 1h TTL, 256 entries. Replaces a global Mutex<HashMap> scanned O(n) per retry receipt.

§session_locks_capacity: u64

Per-device Signal session lock capacity. Default: 10000. Soft cap: a lock a task is actively holding is never evicted, so the map can briefly exceed this under heavy concurrent fan-out (bounded by the concurrently-held count) rather than evicting a live lock and letting two writers race the same session.

§chat_lanes_capacity: u64

Per-chat lane capacity (combined lock + queue). Default: 5000.

§group_distribution_locks_capacity: u64

Per-group cold sender-key distribution lock capacity. Default: 512. Soft cap: a live lane is never evicted, so the map may briefly exceed this under concurrent fan-out instead of breaking tracker ordering.

§resend_rate_limiter_capacity: u64

Per-chat resend rate-limiter capacity: one token-bucket entry per group recently driving retry resends. Keep above the count of concurrently storming groups: eviction is FIFO and fail-open (an evicted bucket is recreated full), so undersizing only forgives rate, never over-throttles. Default: 4096.

§sent_message_ttl_secs: u64

TTL in seconds for sent messages in DB before periodic cleanup. Must outlive retry receipts (which can arrive well after a send) or the retry is dropped as “not found in cache”. The periodic sweep keeps the table bounded. 0 = no automatic cleanup. Default: 7200 (2 hours).

§msg_secret_policy: MsgSecretPolicy

How the per-message messageSecret store is managed (capture / seed / prune). Default MsgSecretPolicy::Managed bounds DB growth: it seeds only the still-relevant slice of history and prunes by a per-add-on-kind event-time horizon. Set MsgSecretPolicy::Full to keep everything forever, or MsgSecretPolicy::Disabled to persist nothing and delegate to original_message_resolver.

§msg_secret_retention: MsgSecretRetention

Per-add-on-kind retention horizons applied under Managed/BotOnly.

§seed_msg_secrets_from_history: bool

Whether to seed messageSecrets from history-sync blobs. Default true.

Independent of live capture (which msg_secret_policy governs): seeding only matters for add-ons that arrive live after connect yet reference a parent delivered via history sync — edits of just-pre-pairing messages, add-options/edits on still-open polls, or replays to a reconnecting offline device. Headless consumers that only react to new messages can set this to false to skip the pairing-time seed entirely. When true, the policy still filters the seed (age/type under Managed, bot-only under BotOnly, everything under Full).

§original_message_resolver: Option<Arc<dyn OriginalMessageResolver>>

Optional app-supplied fallback consulted when an add-on’s parent secret is absent from the store (and its LID/PN alternates). Lets an app that keeps its own message store own secret retention; required for the Disabled policy to decrypt anything beyond what it has seen live.

§msg_secret_resolver_timeout: Duration

Bound on each original_message_resolver call. The resolver runs inside the per-chat receive lane, so a slow callback would stall that chat; on timeout the lookup degrades to a miss. Default: 5s.

§cache_stores: CacheStores

Per-cache custom store overrides.

For each field set to Some(store), the corresponding cache uses that backend instead of the default in-process cache. Fields left as None keep the default in-process behaviour.

Coordination caches (session_locks, chat_lanes), the signal write-behind cache, and pdo_pending_requests always stay in-process — they hold live Rust objects (mutexes, channel senders, oneshot senders) that cannot be serialised to an external store.

Trait Implementations§

Source§

impl Clone for CacheConfig

Source§

fn clone(&self) -> CacheConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AggregateExpressionMethods for T

Source§

fn aggregate_distinct(self) -> Self::Output
where Self: DistinctDsl,

DISTINCT modifier for aggregate functions Read more
Source§

fn aggregate_all(self) -> Self::Output
where Self: AllDsl,

ALL modifier for aggregate functions Read more
Source§

fn aggregate_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add an aggregate function filter Read more
Source§

fn aggregate_order<O>(self, o: O) -> Self::Output
where Self: OrderAggregateDsl<O>,

Add an aggregate function order Read more
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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoSql for T

Source§

fn into_sql<T>(self) -> Self::Expression

Convert self to an expression for Diesel’s query builder. Read more
Source§

fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression
where &'a Self: AsExpression<T>, T: SqlType + TypedExpressionType,

Convert &self to an expression for Diesel’s query builder. Read more
Source§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Spawnable for T
where T: Send + 'static,

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<T> WindowExpressionMethods for T

Source§

fn over(self) -> Self::Output
where Self: OverDsl,

Turn a function call into a window function call Read more
Source§

fn window_filter<P>(self, f: P) -> Self::Output
where P: AsExpression<Bool>, Self: FilterDsl<<P as AsExpression<Bool>>::Expression>,

Add a filter to the current window function Read more
Source§

fn partition_by<E>(self, expr: E) -> Self::Output
where Self: PartitionByDsl<E>,

Add a partition clause to the current window function Read more
Source§

fn window_order<E>(self, expr: E) -> Self::Output
where Self: OrderWindowDsl<E>,

Add a order clause to the current window function Read more
Source§

fn frame_by<E>(self, expr: E) -> Self::Output
where Self: FrameDsl<E>,

Add a frame clause to the current window function Read more