add: shared structs, caching services, import task change
This commit is contained in:
41 files changed
+875
-770
No files matched your search
@@ -0,0 +1,35 @@
|
||||
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;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user