diff --git a/crates/router/src/db/cache.rs b/crates/router/src/db/cache.rs index d9db13dde8..ba0aae55e8 100644 --- a/crates/router/src/db/cache.rs +++ b/crates/router/src/db/cache.rs @@ -88,7 +88,7 @@ where Fut: futures::Future> + Send, { let data = fun().await?; - in_memory.async_map(|cache| cache.invalidate(key)).await; + in_memory.async_map(|cache| cache.remove(key)).await; let redis_conn = store .get_redis_conn() diff --git a/crates/router/tests/cache.rs b/crates/router/tests/cache.rs index 040e0dddf9..c6eef06db7 100644 --- a/crates/router/tests/cache.rs +++ b/crates/router/tests/cache.rs @@ -50,8 +50,14 @@ async fn invalidate_existing_cache_success() { let response_body = response.body().await; println!("invalidate Cache: {response:?} : {response_body:?}"); assert_eq!(response.status(), awc::http::StatusCode::OK); - assert!(cache::CONFIG_CACHE.get(&cache_key).await.is_none()); - assert!(cache::ACCOUNTS_CACHE.get(&cache_key).await.is_none()); + assert!(cache::CONFIG_CACHE + .get_val::(&cache_key) + .await + .is_none()); + assert!(cache::ACCOUNTS_CACHE + .get_val::(&cache_key) + .await + .is_none()); } #[actix_web::test] diff --git a/crates/storage_impl/src/redis/cache.rs b/crates/storage_impl/src/redis/cache.rs index dc2a2225dc..4cd2fc0c50 100644 --- a/crates/storage_impl/src/redis/cache.rs +++ b/crates/storage_impl/src/redis/cache.rs @@ -94,13 +94,6 @@ pub struct Cache { inner: MokaCache>, } -impl std::ops::Deref for Cache { - type Target = MokaCache>; - fn deref(&self) -> &Self::Target { - &self.inner - } -} - impl Cache { /// With given `time_to_live` and `time_to_idle` creates a moka cache. /// @@ -122,16 +115,16 @@ impl Cache { } pub async fn push(&self, key: String, val: T) { - self.insert(key, Arc::new(val)).await; + self.inner.insert(key, Arc::new(val)).await; } pub async fn get_val(&self, key: &str) -> Option { - let val = self.get(key).await?; + let val = self.inner.get(key).await?; (*val).as_any().downcast_ref::().cloned() } pub async fn remove(&self, key: &str) { - self.invalidate(key).await; + self.inner.invalidate(key).await; } } @@ -208,7 +201,7 @@ where Fut: futures::Future> + Send, { let data = fun().await?; - in_memory.async_map(|cache| cache.invalidate(key)).await; + in_memory.async_map(|cache| cache.remove(key)).await; let redis_conn = store .get_redis_conn() diff --git a/crates/storage_impl/src/redis/pub_sub.rs b/crates/storage_impl/src/redis/pub_sub.rs index 349d1872d2..2922dbcadb 100644 --- a/crates/storage_impl/src/redis/pub_sub.rs +++ b/crates/storage_impl/src/redis/pub_sub.rs @@ -60,16 +60,16 @@ impl PubSubInterface for redis_interface::RedisConnectionPool { let key = match key { CacheKind::Config(key) => { - CONFIG_CACHE.invalidate(key.as_ref()).await; + CONFIG_CACHE.remove(key.as_ref()).await; key } CacheKind::Accounts(key) => { - ACCOUNTS_CACHE.invalidate(key.as_ref()).await; + ACCOUNTS_CACHE.remove(key.as_ref()).await; key } CacheKind::All(key) => { - CONFIG_CACHE.invalidate(key.as_ref()).await; - ACCOUNTS_CACHE.invalidate(key.as_ref()).await; + CONFIG_CACHE.remove(key.as_ref()).await; + ACCOUNTS_CACHE.remove(key.as_ref()).await; key } };