35 lines
886 B
Rust
35 lines
886 B
Rust
use cache::Expiration;
|
|||
|
|
use crate::state::{AppInternalState, AppState};
|
||
|
|
use serde::de::DeserializeOwned;
|
||
|
|
use serde::Serialize;
|
||
|
|
|
||
|
|
pub async fn projects_cache<T: DeserializeOwned>(
|
||
|
|
app_state: &mut AppInternalState,
|
||
|
|
key: String,
|
||
|
|
) -> Option<T> {
|
||
|
|
app_state
|
||
|
|
.cache
|
||
|
|
.get(format!("projects:{key}"))
|
||
|
|
.await
|
||
|
|
.unwrap_or(None)
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn set_projects_cache<T>(app_state: &AppState, key: String, value: T, expiration: Expiration)
|
||
|
|
where
|
||
|
|
T: Serialize + DeserializeOwned + Send + Sync + 'static,
|
||
|
|
{
|
||
|
|
let app_state = app_state.clone();
|
||
|
|
tokio::spawn(async move {
|
||
|
|
let mut s = app_state.lock().await;
|
||
|
|
let _ = s
|
||
|
|
.cache
|
||
|
|
.set(
|
||
|
|
format!("projects:{key}"),
|
||
|
|
&value,
|
||
|
|
Some(expiration),
|
||
|
|
None,
|
||
|
|
false,
|
||
|
|
)
|
||
|
|
.await;
|
||
|
|
});
|
||
|
|
}
|