mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-11-03 05:17:02 +08:00
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Arun Raj M <jarnura47@gmail.com>
29 lines
949 B
Rust
29 lines
949 B
Rust
use common_utils::errors::CustomResult;
|
|
use error_stack::{report, ResultExt};
|
|
use storage_impl::redis::cache::{publish_into_redact_channel, CacheKind};
|
|
|
|
use super::errors;
|
|
use crate::{routes::SessionState, services};
|
|
|
|
pub async fn invalidate(
|
|
state: SessionState,
|
|
key: &str,
|
|
) -> CustomResult<services::api::ApplicationResponse<serde_json::Value>, errors::ApiErrorResponse> {
|
|
let store = state.store.as_ref();
|
|
let result = publish_into_redact_channel(
|
|
store.get_cache_store().as_ref(),
|
|
[CacheKind::All(key.into())],
|
|
)
|
|
.await
|
|
.change_context(errors::ApiErrorResponse::InternalServerError)?;
|
|
|
|
// If the message was published to atleast one channel
|
|
// then return status Ok
|
|
if result > 0 {
|
|
Ok(services::api::ApplicationResponse::StatusOk)
|
|
} else {
|
|
Err(report!(errors::ApiErrorResponse::InternalServerError)
|
|
.attach_printable("Failed to invalidate cache"))
|
|
}
|
|
}
|