cat_gateway/db/index/session/
cache_manager.rs

1//! Manager for the different Caches used by the Cassandra Session.
2use std::sync::Arc;
3
4use crate::db::index::queries::caches::{
5    assets::{ada::AssetsAdaCache, native::AssetsNativeCache},
6    rbac::{
7        chains::ChainsCache, public_key::PublicKeyCache, stake_address::StakeAddressCache,
8        transaction_id::TransactionIdCache,
9    },
10};
11
12/// Manager for the different Caches used by the Cassandra Session.
13pub(crate) struct Caches {
14    /// Cache for TXO ADA Assets by Stake Address (disabled for Volatile Sessions)
15    assets_ada: Arc<AssetsAdaCache>,
16    /// Cache for TXO Native Assets by Stake Address (disabled for Volatile Sessions)
17    assets_native: Arc<AssetsNativeCache>,
18    ///  Cache for RBAC Catalyst IDs by Public Key
19    rbac_public_key: Arc<PublicKeyCache>,
20    ///  Cache for RBAC Catalyst IDs by Stake Address
21    rbac_stake_address: Arc<StakeAddressCache>,
22    ///  Cache for RBAC Catalyst IDs by Transaction ID
23    rbac_transaction_id: Arc<TransactionIdCache>,
24    ///  Cache for RBAC Persistent Chains
25    rbac_persistent_chains: Arc<ChainsCache>,
26}
27
28impl Caches {
29    /// Initialize Session Caches
30    pub(crate) fn new(is_persistent: bool) -> Self {
31        Self {
32            assets_ada: Arc::new(AssetsAdaCache::new(is_persistent)),
33            assets_native: Arc::new(AssetsNativeCache::new(is_persistent)),
34            rbac_public_key: Arc::new(PublicKeyCache::new(is_persistent)),
35            rbac_stake_address: Arc::new(StakeAddressCache::new(is_persistent)),
36            rbac_transaction_id: Arc::new(TransactionIdCache::new(is_persistent)),
37            rbac_persistent_chains: Arc::new(ChainsCache::new(is_persistent)),
38        }
39    }
40
41    /// UTXO Native Assets Cache
42    pub(crate) fn assets_native(&self) -> Arc<AssetsNativeCache> {
43        self.assets_native.clone()
44    }
45
46    /// UTXO ADA Assets Cache
47    pub(crate) fn assets_ada(&self) -> Arc<AssetsAdaCache> {
48        self.assets_ada.clone()
49    }
50
51    /// RBAC Public Key Cache
52    pub(crate) fn rbac_public_key(&self) -> Arc<PublicKeyCache> {
53        self.rbac_public_key.clone()
54    }
55
56    /// RBAC Stake Address Cache
57    pub(crate) fn rbac_stake_address(&self) -> Arc<StakeAddressCache> {
58        self.rbac_stake_address.clone()
59    }
60
61    /// RBAC Transaction Id Cache
62    pub(crate) fn rbac_transaction_id(&self) -> Arc<TransactionIdCache> {
63        self.rbac_transaction_id.clone()
64    }
65
66    /// RBAC Chains Cache
67    pub(crate) fn rbac_persistent_chains(&self) -> Arc<ChainsCache> {
68        self.rbac_persistent_chains.clone()
69    }
70}