Skip to content

Commit

Permalink
Limit PMTiles cache 4MB per file (#1095)
Browse files Browse the repository at this point in the history
More precursor work for #1093
  • Loading branch information
nyurik authored Dec 24, 2023
1 parent a68ebcd commit acb52f2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions martin/src/pmtiles/http_pmtiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,15 @@ use crate::{MartinResult, TileCoord, TileData};
struct PmtCache(Cache<usize, Directory>);

impl PmtCache {
fn new() -> Self {
Self(Cache::new(500))
fn new(max_capacity: u64) -> Self {
Self(
Cache::builder()
.weigher(|_key, value: &Directory| -> u32 {
value.get_approx_byte_size().try_into().unwrap_or(u32::MAX)
})
.max_capacity(max_capacity)
.build(),
)
}
}

Expand Down Expand Up @@ -54,7 +61,7 @@ impl_pmtiles_source!(
impl PmtHttpSource {
pub async fn new_url_box(id: String, url: Url) -> FileResult<Box<dyn Source>> {
let client = Client::new();
let cache = PmtCache::new();
let cache = PmtCache::new(4 * 1024 * 1024);
Ok(Box::new(
PmtHttpSource::new_url(client, cache, id, url).await?,
))
Expand Down

0 comments on commit acb52f2

Please sign in to comment.