mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
feat(routing): success based routing metrics (#5951)
Co-authored-by: Aprabhat19 <amishaprabhat@gmail.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Amisha Prabhat <55580080+Aprabhat19@users.noreply.github.com>
This commit is contained in:
@ -72,6 +72,16 @@ pub static PM_FILTERS_CGRAPH_CACHE: Lazy<Cache> = Lazy::new(|| {
|
||||
)
|
||||
});
|
||||
|
||||
/// Dynamic Algorithm Cache
|
||||
pub static SUCCESS_BASED_DYNAMIC_ALGORITHM_CACHE: Lazy<Cache> = Lazy::new(|| {
|
||||
Cache::new(
|
||||
"SUCCESS_BASED_DYNAMIC_ALGORITHM_CACHE",
|
||||
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;
|
||||
@ -91,6 +101,7 @@ pub enum CacheKind<'a> {
|
||||
DecisionManager(Cow<'a, str>),
|
||||
Surcharge(Cow<'a, str>),
|
||||
CGraph(Cow<'a, str>),
|
||||
SuccessBasedDynamicRoutingCache(Cow<'a, str>),
|
||||
PmFiltersCGraph(Cow<'a, str>),
|
||||
All(Cow<'a, str>),
|
||||
}
|
||||
|
||||
@ -6,7 +6,8 @@ use router_env::{logger, tracing::Instrument};
|
||||
|
||||
use crate::redis::cache::{
|
||||
CacheKey, CacheKind, CacheRedact, ACCOUNTS_CACHE, CGRAPH_CACHE, CONFIG_CACHE,
|
||||
DECISION_MANAGER_CACHE, PM_FILTERS_CGRAPH_CACHE, ROUTING_CACHE, SURCHARGE_CACHE,
|
||||
DECISION_MANAGER_CACHE, PM_FILTERS_CGRAPH_CACHE, ROUTING_CACHE,
|
||||
SUCCESS_BASED_DYNAMIC_ALGORITHM_CACHE, SURCHARGE_CACHE,
|
||||
};
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@ -137,6 +138,15 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
|
||||
.await;
|
||||
key
|
||||
}
|
||||
CacheKind::SuccessBasedDynamicRoutingCache(key) => {
|
||||
SUCCESS_BASED_DYNAMIC_ALGORITHM_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
prefix: message.tenant.clone(),
|
||||
})
|
||||
.await;
|
||||
key
|
||||
}
|
||||
CacheKind::Routing(key) => {
|
||||
ROUTING_CACHE
|
||||
.remove(CacheKey {
|
||||
@ -189,6 +199,12 @@ impl PubSubInterface for std::sync::Arc<redis_interface::RedisConnectionPool> {
|
||||
prefix: message.tenant.clone(),
|
||||
})
|
||||
.await;
|
||||
SUCCESS_BASED_DYNAMIC_ALGORITHM_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
prefix: message.tenant.clone(),
|
||||
})
|
||||
.await;
|
||||
ROUTING_CACHE
|
||||
.remove(CacheKey {
|
||||
key: key.to_string(),
|
||||
|
||||
Reference in New Issue
Block a user