Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.1 kB View raw
1use crate::CachedRecord; 2use foyer::{ 3 BlockEngineConfig, DeviceBuilder, FsDeviceBuilder, HybridCache, HybridCacheBuilder, 4 PsyncIoEngineConfig, 5}; 6use std::path::Path; 7 8pub async fn firehose_cache( 9 cache_dir: impl AsRef<Path>, 10 memory_mb: usize, 11 disk_gb: usize, 12) -> Result<HybridCache<String, CachedRecord>, String> { 13 let device = FsDeviceBuilder::new(cache_dir) 14 .with_capacity(disk_gb * 2_usize.pow(30)) 15 .build() 16 .map_err(|e| format!("foyer device setup error: {e}"))?; 17 18 let engine = BlockEngineConfig::new(device).with_block_size(16 * 2_usize.pow(20)); // note: this does limit the max cached item size 19 20 let cache = HybridCacheBuilder::new() 21 .with_name("firehose") 22 .memory(memory_mb * 2_usize.pow(20)) 23 .with_weighter(|k: &String, v: &CachedRecord| { 24 std::mem::size_of_val(k.as_str()) + v.weight() 25 }) 26 .storage() 27 .with_io_engine_config(PsyncIoEngineConfig::default()) 28 .with_engine_config(engine) 29 .build() 30 .await 31 .map_err(|e| format!("foyer setup error: {e:?}"))?; 32 33 Ok(cache) 34}