Skip to main content

distributed_cache/
lib.rs

1//
2// Copyright 2018-2026 Accenture Technology
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16
17//! **The distributed cache** — Rust port of the Java engine's
18//! `extensions/distributed-cache` (`org.platformlambda.cache`, v4.12.9;
19//! design spec `draft-design-specs/distributed-cache.md` in the Java repo,
20//! Q1–Q8; this port's spec `draft-design-specs/distributed-cache-port.md`).
21//!
22//! A generic Redis-backed L2 key-value cache exposed as **one composable
23//! action function**, route [`CACHE_ROUTE`] (`v1.cache.redis`), over opaque
24//! byte values — the caller owns serialisation, which is what lets any layer
25//! and any language share the cache. An `action` header selects the
26//! operation; key(s) and TTL ride in headers, value(s) in the body.
27//!
28//! | Type | Java class | Role |
29//! |---|---|---|
30//! | [`CacheAction`] | `CacheAction` | the bounded, cache-shaped operation set |
31//! | [`CacheConfig`] | `CacheConfig` | `redis.cache.*` tunables over the plain `redis.*` connection namespace |
32//! | [`RedisCacheStore`] | `RedisCacheStore` | the operations over the shared `RedisBackend` — cluster-safe, every key TTL'd from birth |
33//! | [`runtime`] | `CacheRuntime` | the process-wide, lazily built store over ONE multiplexed connection |
34//! | [`RedisCache`] | `RedisCache` | the `#[preload]` function `v1.cache.redis`, gated by `redis.cache.enabled` |
35//! | [`CacheRedisHealthCheck`] | `CacheRedisHealthCheck` | the `redis.health` binding of the foundation's probe |
36//!
37//! Two composable functions self-register when this crate is linked into an
38//! application AND `redis.cache.enabled=true` (reference the crate from
39//! `main.rs` so the linker keeps its registration inventory — the Java
40//! "include the jar" deployment story):
41//!
42//! - **`v1.cache.redis`** — the cache; `redis.cache.instances` (default 20)
43//!   is worker concurrency, NOT a connection count: every worker shares the
44//!   one multiplexed connection the runtime holds.
45//! - **`redis.health`** — the `/health` probe of the cache's Redis; add it to
46//!   `mandatory.health.dependencies` or `optional.health.dependencies`.
47//!
48//! This crate is imported by the APPLICATION, never by the engine — a cache
49//! is a deployment choice. It does not depend on sync-over-async; both depend
50//! on the `redis-connection` foundation, in the Java dependency direction.
51//!
52//! **Cross-engine contract.** Cache keys are plain Redis keys
53//! (`{redis.cache.key.prefix}{key}`), values are the caller's bytes, the
54//! action names and the configuration keys are the Java engine's — so a Java
55//! pod and a Rust pod configured alike read and write one cache.
56
57mod action;
58mod config;
59mod function;
60mod health;
61pub mod runtime;
62mod store;
63
64pub use action::CacheAction;
65pub use config::{
66    CacheConfig, CACHE_ENABLED_KEY, CACHE_INSTANCES_KEY, DEFAULT_TTL_KEY, KEY_PREFIX_KEY,
67};
68pub use function::{handle, RedisCache, CACHE_ROUTE};
69pub use health::{CacheRedisHealthCheck, HEALTH_ROUTE};
70pub use store::RedisCacheStore;