Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
1use crate::CachedRecord; 2use foyer::{DirectFsDeviceOptions, Engine, HybridCache, HybridCacheBuilder}; 3use std::path::Path; 4 5pub async fn firehose_cache( 6 cache_dir: impl AsRef<Path>, 7) -> Result<HybridCache<String, CachedRecord>, String> { 8 let cache = HybridCacheBuilder::new() 9 .with_name("firehose") 10 .memory(64 * 2_usize.pow(20)) 11 .with_weighter(|k: &String, v| k.len() + std::mem::size_of_val(v)) 12 .storage(Engine::large()) 13 .with_device_options( 14 DirectFsDeviceOptions::new(cache_dir) 15 .with_capacity(2_usize.pow(30)) // TODO: configurable (1GB to have something) 16 .with_file_size(16 * 2_usize.pow(20)), // note: this does limit the max cached item size, warning jumbo records 17 ) 18 .build() 19 .await 20 .map_err(|e| format!("foyer setup error: {e:?}"))?; 21 Ok(cache) 22}