#[derive(Debug, Clone)]
pub struct CacheConfig {
#[cfg(feature = "_tiles")]
pub tile_cache_size_mb: u64,
#[cfg(feature = "pmtiles")]
pub pmtiles_cache_size_mb: u64,
#[cfg(feature = "sprites")]
pub sprite_cache_size_mb: u64,
#[cfg(feature = "fonts")]
pub font_cache_size_mb: u64,
}
impl CacheConfig {
#[cfg(feature = "_tiles")]
#[must_use]
pub fn create_tile_cache(&self) -> Option<martin_core::tiles::TileCache> {
if self.tile_cache_size_mb > 0 {
tracing::info!(
"Initializing tile cache with maximum size {} MB",
self.tile_cache_size_mb
);
let size = self.tile_cache_size_mb * 1000 * 1000;
Some(martin_core::tiles::TileCache::new(size))
} else {
tracing::info!("Tile caching is disabled");
None
}
}
#[cfg(feature = "pmtiles")]
#[must_use]
pub fn create_pmtiles_cache(&self) -> martin_core::tiles::pmtiles::PmtCache {
if self.pmtiles_cache_size_mb > 0 {
tracing::info!(
"Initializing PMTiles directory cache with maximum size {} MB",
self.pmtiles_cache_size_mb
);
let size = self.pmtiles_cache_size_mb * 1000 * 1000;
martin_core::tiles::pmtiles::PmtCache::new(size)
} else {
tracing::debug!("PMTiles directory caching is disabled");
martin_core::tiles::pmtiles::PmtCache::new(0)
}
}
#[cfg(feature = "sprites")]
#[must_use]
pub fn create_sprite_cache(&self) -> martin_core::sprites::OptSpriteCache {
if self.sprite_cache_size_mb > 0 {
tracing::info!(
"Initializing sprite cache with maximum size {} MB",
self.sprite_cache_size_mb
);
let size = self.sprite_cache_size_mb * 1000 * 1000;
Some(martin_core::sprites::SpriteCache::new(size))
} else {
tracing::info!("Sprite caching is disabled");
None
}
}
#[cfg(feature = "fonts")]
#[must_use]
pub fn create_font_cache(&self) -> martin_core::fonts::OptFontCache {
if self.font_cache_size_mb > 0 {
tracing::info!(
"Initializing font cache with maximum size {} MB",
self.font_cache_size_mb
);
let size = self.font_cache_size_mb * 1000 * 1000;
Some(martin_core::fonts::FontCache::new(size))
} else {
tracing::info!("Font caching is disabled");
None
}
}
}