cat_gateway/db/index/queries/caches/rbac/
chains.rs1use catalyst_types::catalyst_id::CatalystId;
4use moka::policy::EvictionPolicy;
5use rbac_registration::registration::cardano::RegistrationChain;
6
7use crate::{service::utilities::cache::Cache, settings::Settings};
8
9pub(crate) struct ChainsCache {
11 inner: Cache<CatalystId, RegistrationChain>,
13}
14
15impl ChainsCache {
16 const CACHE_NAME: &str = "RBAC Persistent Chains Cache";
18
19 pub(crate) fn new(is_persistent: bool) -> Self {
26 let max_capacity = if is_persistent {
27 Settings::rbac_cfg().persistent_chains_cache_size
28 } else {
29 0
30 };
31 Self {
32 inner: Cache::new(Self::CACHE_NAME, EvictionPolicy::lru(), max_capacity),
33 }
34 }
35
36 pub(crate) fn get(
38 &self,
39 key: &CatalystId,
40 ) -> Option<RegistrationChain> {
41 self.inner.get(key)
42 }
43
44 pub(crate) fn insert(
46 &self,
47 key: CatalystId,
48 value: RegistrationChain,
49 ) {
50 self.inner.insert(key, value);
51 }
52
53 pub(crate) fn weighted_size(&self) -> u64 {
55 self.inner.weighted_size()
56 }
57
58 pub(crate) fn entry_count(&self) -> u64 {
60 self.inner.entry_count()
61 }
62
63 pub(crate) fn is_enabled(&self) -> bool {
65 self.inner.is_enabled()
66 }
67}