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

ambee/giterated

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

Re-expose Operation State in generics.

This is the worst code I have ever written. I hate the way this changes everything. ugh.

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨90db3e2

⁨giterated-cache/src/lib.rs⁩ - ⁨900⁩ bytes
Raw
1 use cache_get::get_cached;
2 use giterated_stack::{AnyValue, StackOperationState, 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, StackOperationState> {
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