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/lib.rs⁩ - ⁨858⁩ bytes
Raw
1 use cache_get::get_cached;
2 use giterated_stack::{AnyValue, SubstackBuilder};
3 use moka::future::Cache;
4
5 use crate::cache_update::cache_updated;
6
7 pub mod cache_get;
8 pub mod cache_update;
9
10 // use giterated_stack::{ObjectValuePair, SubstackBuilder};
11 // use moka::future::Cache;
12 // use serde_json::Value;
13
14 #[derive(Hash, PartialEq, Eq)]
15 pub struct CacheKey {
16 object: String,
17 value_name: String,
18 }
19
20 #[derive(Clone)]
21 pub struct CacheSubstack {
22 cache: Cache<CacheKey, AnyValue>,
23 }
24
25 impl Default for CacheSubstack {
26 fn default() -> Self {
27 Self {
28 cache: Cache::new(20_000),
29 }
30 }
31 }
32
33 impl CacheSubstack {
34 pub fn into_substack(self) -> SubstackBuilder<Self> {
35 let mut stack = SubstackBuilder::new(self);
36
37 stack.value_change(cache_updated);
38 stack.dynamic_value(get_cached);
39
40 stack
41 }
42 }
43