camel_api/stream_cache.rs
1/// Default stream cache threshold (128 KB).
2///
3/// Streams exceeding this size will fail with [`CamelError::StreamLimitExceeded`].
4/// This is intentionally conservative for OOM protection.
5/// For general-purpose materialization, use [`Body::materialize()`] (10 MB default).
6pub const DEFAULT_STREAM_CACHE_THRESHOLD: usize = 128 * 1024;
7
8/// Configuration for [`StreamCacheService`](camel_processor::StreamCacheService).
9///
10/// Controls the maximum bytes a `Body::Stream` may consume when materialized
11/// into `Body::Bytes`. Can be set globally via `[stream_caching]` in Camel.toml
12/// or per-step via `stream_cache: { threshold: N }` in YAML routes.
13#[derive(Debug, Clone, Copy)]
14pub struct StreamCacheConfig {
15 /// Maximum bytes to buffer when materializing a stream.
16 pub threshold: usize,
17}
18
19impl Default for StreamCacheConfig {
20 fn default() -> Self {
21 Self {
22 threshold: DEFAULT_STREAM_CACHE_THRESHOLD,
23 }
24 }
25}
26
27impl StreamCacheConfig {
28 /// Create a new config with the given threshold in bytes.
29 pub fn new(threshold: usize) -> Self {
30 Self { threshold }
31 }
32}