Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Release build
on:
push:
branches:
- release/**
- not-release/**

jobs:
linux:
Expand Down
81 changes: 43 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/symbolicator-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jsonwebtoken = "8.1.0"
lazy_static = "1.4.0"
minidump = "0.16.0"
minidump-processor = "0.16.0"
moka = { version = "0.10", features = ["future"] }
moka = { git = "https://github.com/moka-rs/moka.git", features = ["future"] }
parking_lot = "0.12.0"
regex = "1.5.5"
reqwest = { version = "0.11.0", features = ["gzip", "json", "stream", "trust-dns"] }
Expand Down
36 changes: 32 additions & 4 deletions crates/symbolicator-service/src/caching/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,42 @@ impl<T: CacheItemRequest> Clone for Cacher<T> {
}
}

/// A struct implementing [`moka::Expiry`] that uses the [`InMemoryItem`] [`Instant`] as the explicit
/// expiration time.
struct CacheExpiration;
fn saturating_duration_since(now: Instant, target: Instant) -> Option<Duration> {
// NOTE: the argument to `checked_duration_since` is the *earlier* instant.
// `target` is in the future, and `now` is the earlier one.
Some(target.checked_duration_since(now).unwrap_or_default())
}

impl<T> moka::Expiry<CacheKey, InMemoryItem<T>> for CacheExpiration {
fn expire_after_create(
&self,
_key: &CacheKey,
value: &InMemoryItem<T>,
current_time: Instant,
) -> Option<Duration> {
saturating_duration_since(current_time, value.0)
}

fn expire_after_update(
&self,
_key: &CacheKey,
value: &InMemoryItem<T>,
current_time: Instant,
_current_duration: Option<Duration>,
) -> Option<Duration> {
saturating_duration_since(current_time, value.0)
}
}

impl<T: CacheItemRequest> Cacher<T> {
pub fn new(config: Cache, shared_cache: SharedCacheRef) -> Self {
let cache = InMemoryCache::builder()
.max_capacity(config.in_memory_capacity)
.name(config.name().as_ref())
// NOTE: even though we have a per-item TTL, we still want to have a hard limit here
.time_to_live(Duration::from_secs(60 * 60))
.expire_after(CacheExpiration)
// NOTE: we count all the bookkeeping structures to the weight as well
.weigher(|_k, v| {
let value_size =
Expand Down Expand Up @@ -367,12 +396,11 @@ impl<T: CacheItemRequest> Cacher<T> {

(expiration.as_instant(), item)
});
let replace_if = |v: &InMemoryItem<T::Item>| Instant::now() >= v.0;

let entry = self
.cache
.entry_by_ref(&cache_key)
.or_insert_with_if(init, replace_if)
.or_insert_with(init)
.await;

if !entry.is_fresh() {
Expand Down
2 changes: 1 addition & 1 deletion gocd/pipelines/symbolicator-canary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pipelines:
symbolicator_repo:
git: [email protected]:getsentry/symbolicator.git
shallow_clone: true
branch: master
branch: release/moka-expiry
destination: symbolicator
stages:
- checks:
Expand Down