Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/stackable-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Add `TtlCache` structure ([#943]).

[#943]: https://github.com/stackabletech/operator-rs/pull/943

## [0.84.0] - 2025-01-16

### Added
Expand Down
38 changes: 38 additions & 0 deletions crates/stackable-operator/src/commons/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::time::Duration;

/// Least Recently Used (LRU) cache with per-entry time-to-live (TTL) value.
#[derive(Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct TtlCache {
/// Time to live per entry; Entries which were not queried within the given duration, are
/// removed.
#[serde(default = "TtlCache::default_entry_time_to_live")]
pub entry_time_to_live: Duration,

/// Maximum number of entries in the cache; If this threshold is reached then the least
/// recently used item is removed.
#[serde(default = "TtlCache::default_max_entries")]
pub max_entries: u32,
}

impl TtlCache {
const fn default_entry_time_to_live() -> Duration {
Duration::from_secs(30)
}

const fn default_max_entries() -> u32 {
1000
}
}

impl Default for TtlCache {
fn default() -> Self {
Self {
entry_time_to_live: Self::default_entry_time_to_live(),
max_entries: Self::default_max_entries(),
}
}
}
1 change: 1 addition & 0 deletions crates/stackable-operator/src/commons/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod affinity;
pub mod authentication;
pub mod cache;
pub mod cluster_operation;
pub mod listener;
pub mod networking;
Expand Down
Loading