mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
Refactor(core): Inclusion of constraint graph for merchant Payment Method list (#4845)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: shashank_attarde <shashank.attarde@juspay.in>
This commit is contained in:
@ -31,6 +31,9 @@ const ROUTING_CACHE_PREFIX: &str = "routing";
|
||||
/// Prefix for cgraph cache key
|
||||
const CGRAPH_CACHE_PREFIX: &str = "cgraph";
|
||||
|
||||
/// Prefix for PM Filter cgraph cache key
|
||||
const PM_FILTERS_CGRAPH_CACHE_PREFIX: &str = "pm_filters_cgraph";
|
||||
|
||||
/// Prefix for all kinds of cache key
|
||||
const ALL_CACHE_PREFIX: &str = "all_cache_kind";
|
||||
|
||||
@ -58,6 +61,10 @@ pub static ROUTING_CACHE: Lazy<Cache> =
|
||||
pub static CGRAPH_CACHE: Lazy<Cache> =
|
||||
Lazy::new(|| Cache::new(CACHE_TTL, CACHE_TTI, Some(MAX_CAPACITY)));
|
||||
|
||||
/// PM Filter CGraph Cache
|
||||
pub static PM_FILTERS_CGRAPH_CACHE: Lazy<Cache> =
|
||||
Lazy::new(|| Cache::new(CACHE_TTL, CACHE_TTI, Some(MAX_CAPACITY)));
|
||||
|
||||
/// Trait which defines the behaviour of types that's gonna be stored in Cache
|
||||
pub trait Cacheable: Any + Send + Sync + DynClone {
|
||||
fn as_any(&self) -> &dyn Any;
|
||||
@ -68,6 +75,7 @@ pub enum CacheKind<'a> {
|
||||
Accounts(Cow<'a, str>),
|
||||
Routing(Cow<'a, str>),
|
||||
CGraph(Cow<'a, str>),
|
||||
PmFiltersCGraph(Cow<'a, str>),
|
||||
All(Cow<'a, str>),
|
||||
}
|
||||
|
||||
@ -78,6 +86,7 @@ impl<'a> From<CacheKind<'a>> for RedisValue {
|
||||
CacheKind::Accounts(s) => format!("{ACCOUNTS_CACHE_PREFIX},{s}"),
|
||||
CacheKind::Routing(s) => format!("{ROUTING_CACHE_PREFIX},{s}"),
|
||||
CacheKind::CGraph(s) => format!("{CGRAPH_CACHE_PREFIX},{s}"),
|
||||
CacheKind::PmFiltersCGraph(s) => format!("{PM_FILTERS_CGRAPH_CACHE_PREFIX},{s}"),
|
||||
CacheKind::All(s) => format!("{ALL_CACHE_PREFIX},{s}"),
|
||||
};
|
||||
Self::from_string(value)
|
||||
@ -97,6 +106,9 @@ impl<'a> TryFrom<RedisValue> for CacheKind<'a> {
|
||||
CONFIG_CACHE_PREFIX => Ok(Self::Config(Cow::Owned(split.1.to_string()))),
|
||||
ROUTING_CACHE_PREFIX => Ok(Self::Routing(Cow::Owned(split.1.to_string()))),
|
||||
CGRAPH_CACHE_PREFIX => Ok(Self::CGraph(Cow::Owned(split.1.to_string()))),
|
||||
PM_FILTERS_CGRAPH_CACHE_PREFIX => {
|
||||
Ok(Self::PmFiltersCGraph(Cow::Owned(split.1.to_string())))
|
||||
}
|
||||
ALL_CACHE_PREFIX => Ok(Self::All(Cow::Owned(split.1.to_string()))),
|
||||
_ => Err(validation_err.into()),
|
||||
}
|
||||
|
||||
@ -3,7 +3,8 @@ use redis_interface::{errors as redis_errors, PubsubInterface, RedisValue};
|
||||
use router_env::{logger, tracing::Instrument};
|
||||
|
||||
use crate::redis::cache::{
|
||||
CacheKey, CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, ROUTING_CACHE,
|
||||
CacheKey, CacheKind, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE, PM_FILTERS_CGRAPH_CACHE,
|
||||
ROUTING_CACHE,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -99,6 +100,16 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
|
||||
.await;
|
||||
key
|
||||
}
|
||||
CacheKind::PmFiltersCGraph(key) => {
|
||||
PM_FILTERS_CGRAPH_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
prefix: self.key_prefix.clone(),
|
||||
})
|
||||
.await;
|
||||
|
||||
key
|
||||
}
|
||||
CacheKind::Routing(key) => {
|
||||
ROUTING_CACHE
|
||||
.remove(CacheKey {
|
||||
@ -127,6 +138,12 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
|
||||
prefix: self.key_prefix.clone(),
|
||||
})
|
||||
.await;
|
||||
PM_FILTERS_CGRAPH_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
prefix: self.key_prefix.clone(),
|
||||
})
|
||||
.await;
|
||||
ROUTING_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user