mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-01 19:42:27 +08:00
feat(router): add caching for MerchantKeyStore (#1409)
This commit is contained in:
committed by
GitHub
parent
6563587564
commit
fda3fb4d2b
@ -1,5 +1,7 @@
|
||||
use error_stack::{IntoReport, ResultExt};
|
||||
|
||||
#[cfg(feature = "accounts_cache")]
|
||||
use crate::cache::ACCOUNTS_CACHE;
|
||||
use crate::{
|
||||
connection,
|
||||
core::errors::{self, CustomResult},
|
||||
@ -48,17 +50,40 @@ impl MerchantKeyStoreInterface for Store {
|
||||
&self,
|
||||
merchant_id: &str,
|
||||
) -> CustomResult<merchant_key_store::MerchantKeyStore, errors::StorageError> {
|
||||
let conn = connection::pg_connection_read(self).await?;
|
||||
storage_models::merchant_key_store::MerchantKeyStore::find_by_merchant_id(
|
||||
&conn,
|
||||
merchant_id,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()?
|
||||
.convert(self, merchant_id)
|
||||
.await
|
||||
.change_context(errors::StorageError::DecryptionError)
|
||||
let fetch_func = || async {
|
||||
let conn = connection::pg_connection_read(self).await?;
|
||||
|
||||
storage_models::merchant_key_store::MerchantKeyStore::find_by_merchant_id(
|
||||
&conn,
|
||||
merchant_id,
|
||||
)
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.into_report()
|
||||
};
|
||||
#[cfg(not(feature = "accounts_cache"))]
|
||||
{
|
||||
fetch_func()
|
||||
.await?
|
||||
.convert(self, merchant_id)
|
||||
.await
|
||||
.change_context(errors::StorageError::DecryptionError)
|
||||
}
|
||||
|
||||
#[cfg(feature = "accounts_cache")]
|
||||
{
|
||||
let key_store_cache_key = format!("merchant_key_store_{}", merchant_id);
|
||||
super::cache::get_or_populate_in_memory(
|
||||
self,
|
||||
&key_store_cache_key,
|
||||
fetch_func,
|
||||
&ACCOUNTS_CACHE,
|
||||
)
|
||||
.await?
|
||||
.convert(self, merchant_id)
|
||||
.await
|
||||
.change_context(errors::StorageError::DecryptionError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user