Skip to content

Commit 9606bfc

Browse files
feat(stackable-operator): Add cache structure
1 parent af0d1f1 commit 9606bfc

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

crates/stackable-operator/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Add `TtlCache` structure ([#943]).
10+
11+
[#943]: https://github.com/stackabletech/operator-rs/pull/943
12+
713
## [0.84.0] - 2025-01-16
814

915
### Added
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use schemars::JsonSchema;
2+
use serde::{Deserialize, Serialize};
3+
4+
use crate::time::Duration;
5+
6+
/// Least Recently Used (LRU) cache with per-entry time-to-live (TTL) value.
7+
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
8+
#[serde(rename_all = "camelCase")]
9+
pub struct TtlCache {
10+
/// Time to live per entry; Entries which were not queried within the given duration, are
11+
/// removed.
12+
#[serde(default = "TtlCache::default_entry_time_to_live")]
13+
pub entry_time_to_live: Duration,
14+
15+
/// Maximum number of entries in the cache; If this threshold is reached then the least
16+
/// recently used item is removed.
17+
#[serde(default = "TtlCache::default_max_entries")]
18+
pub max_entries: i32,
19+
}
20+
21+
impl TtlCache {
22+
const fn default_entry_time_to_live() -> Duration {
23+
Duration::from_secs(30)
24+
}
25+
26+
const fn default_max_entries() -> i32 {
27+
1000
28+
}
29+
}
30+
31+
impl Default for TtlCache {
32+
fn default() -> Self {
33+
Self {
34+
entry_time_to_live: Self::default_entry_time_to_live(),
35+
max_entries: Self::default_max_entries(),
36+
}
37+
}
38+
}

crates/stackable-operator/src/commons/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
pub mod affinity;
44
pub mod authentication;
5+
pub mod cache;
56
pub mod cluster_operation;
67
pub mod listener;
78
pub mod networking;

0 commit comments

Comments
 (0)