JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

`giterated_cache` initial implementation

# Giterated Stack - Added the ability for dynamic substack handlers to exist for operations relevant to caching. - Added type metadata to the dynamic types. # Giterated Cache - Created - Implemented caching and fetching from cache. Hell fucking yes!!!! It works so good. Are you snooping in the commit logs because you're curious about the history of giterated? Cool that it got so big... tell me I say hi :)

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨86afeef

⁨giterated-cache/src/cache_update.rs⁩ - ⁨1076⁩ bytes
Raw
1 use std::sync::Arc;
2
3 use giterated_models::error::OperationError;
4 use giterated_stack::{AnyObject, AnyValue, GiteratedStack, StackOperationState};
5 use tracing::trace;
6
7 use crate::{CacheKey, CacheSubstack};
8
9 pub async fn cache_updated(
10 object: AnyObject,
11 value: AnyValue,
12 state: CacheSubstack,
13 _operation_state: StackOperationState,
14 stack: Arc<GiteratedStack>,
15 ) -> Result<(), OperationError<anyhow::Error>> {
16 let object_meta = stack
17 .metadata
18 .objects
19 .get(object.kind())
20 .ok_or_else(|| OperationError::Unhandled)?;
21 let object_str = (object_meta.to_str)(object.clone());
22 let cache_key = CacheKey {
23 object: object_str,
24 value_name: value.kind().value_kind.to_string(),
25 };
26
27 let value_kind = value.kind().value_kind;
28 trace!(
29 "Beginning cache update for {}::{}",
30 object.kind(),
31 value_kind
32 );
33
34 state.cache.insert(cache_key, value).await;
35
36 trace!(
37 "Completed cache update for {}::{}",
38 object.kind(),
39 value_kind
40 );
41 Ok(())
42 }
43