mirror of
				https://github.com/juspay/hyperswitch.git
				synced 2025-10-31 18:17:13 +08:00 
			
		
		
		
	feat(routing): Use Moka cache for routing with cache invalidation (#3216)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
		| @ -10,10 +10,11 @@ use diesel_models::{ | ||||
| }; | ||||
| use error_stack::ResultExt; | ||||
| use rustc_hash::FxHashSet; | ||||
| use storage_impl::redis::cache as redis_cache; | ||||
|  | ||||
| use crate::{ | ||||
|     core::errors::{self, RouterResult}, | ||||
|     db::StorageInterface, | ||||
|     db::{cache, StorageInterface}, | ||||
|     types::{domain, storage}, | ||||
|     utils::StringExt, | ||||
| }; | ||||
| @ -239,6 +240,17 @@ pub async fn update_business_profile_active_algorithm_ref( | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable("Failed to convert routing ref to value")?; | ||||
|  | ||||
|     let merchant_id = current_business_profile.merchant_id.clone(); | ||||
|  | ||||
|     #[cfg(feature = "business_profile_routing")] | ||||
|     let profile_id = current_business_profile.profile_id.clone(); | ||||
|     #[cfg(feature = "business_profile_routing")] | ||||
|     let routing_cache_key = redis_cache::CacheKind::Routing( | ||||
|         format!("routing_config_{merchant_id}_{profile_id}").into(), | ||||
|     ); | ||||
|  | ||||
|     #[cfg(not(feature = "business_profile_routing"))] | ||||
|     let routing_cache_key = redis_cache::CacheKind::Routing(format!("dsl_{merchant_id}").into()); | ||||
|     let (routing_algorithm, payout_routing_algorithm) = match transaction_type { | ||||
|         storage::enums::TransactionType::Payment => (Some(ref_val), None), | ||||
|         #[cfg(feature = "payouts")] | ||||
| @ -272,6 +284,11 @@ pub async fn update_business_profile_active_algorithm_ref( | ||||
|         .await | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable("Failed to update routing algorithm ref in business profile")?; | ||||
|  | ||||
|     cache::publish_into_redact_channel(db, [routing_cache_key]) | ||||
|         .await | ||||
|         .change_context(errors::ApiErrorResponse::InternalServerError) | ||||
|         .attach_printable("Failed to invalidate routing cache")?; | ||||
|     Ok(()) | ||||
| } | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Sarthak Soni
					Sarthak Soni