cat_gateway/settings/
cardano_assets_cache.rs

1//! Environment variable settings for the Cardano assets in memory cache
2
3use crate::settings::str_env_var::StringEnvVar;
4
5/// Default value for the Cardano UTXO cache size (disabled cache)
6const DEFAULT_CARDANO_UTXO_CACHE_SIZE: u64 = 0;
7
8/// Default value for the Cardano native assets cache size (disabled cache)
9const DEFAULT_CARDANO_NATIVE_ASSETS_CACHE_SIZE: u64 = 0;
10
11/// Configuration for Cardano assets in memory cache.
12#[derive(Clone)]
13pub(crate) struct EnvVars {
14    /// Maximum Cardano UTXO cache size value.
15    /// `CARDANO_UTXO_CACHE_SIZE` env var.
16    utxo_cache_size: u64,
17    /// Maximum Cardano native assets cache size value.
18    /// `CARDANO_NATIVE_ASSETS_CACHE_SIZE` env var
19    native_assets_cache_size: u64,
20}
21
22impl EnvVars {
23    /// Create a config for assets in memory cache.
24    pub(super) fn new() -> Self {
25        Self {
26            utxo_cache_size: StringEnvVar::new_as_int(
27                "CARDANO_UTXO_CACHE_SIZE",
28                DEFAULT_CARDANO_UTXO_CACHE_SIZE,
29                0,
30                u64::MAX,
31            ),
32            native_assets_cache_size: StringEnvVar::new_as_int(
33                "CARDANO_NATIVE_ASSETS_CACHE_SIZE",
34                DEFAULT_CARDANO_NATIVE_ASSETS_CACHE_SIZE,
35                0,
36                u64::MAX,
37            ),
38        }
39    }
40
41    /// Returns the maximum size of the Cardano UTXO cache
42    pub(crate) fn utxo_cache_size(&self) -> u64 {
43        self.utxo_cache_size
44    }
45
46    /// Returns the maximum size of the Cardano native asset cache
47    pub(crate) fn native_assets_cache_size(&self) -> u64 {
48        self.native_assets_cache_size
49    }
50}