aboutsummaryrefslogtreecommitdiffstats
path: root/crates/configuration/src/state/cache_key.rs
blob: dd2ad12f396d04b39255e9c8c5de41a1c60ef2d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use warden_stack::redis::ToRedisArgs;

#[derive(Clone, Copy, Debug)]
pub enum CacheKey<'a> {
    ActiveRouting,
    Routing(&'a uuid::Uuid),
    Rule { id: &'a str, version: &'a str },
    Typology { id: &'a str, version: &'a str },
}

impl ToRedisArgs for CacheKey<'_> {
    fn write_redis_args<W>(&self, out: &mut W)
    where
        W: ?Sized + warden_stack::redis::RedisWrite,
    {
        let value = match self {
            CacheKey::ActiveRouting => "routing.active".into(),
            CacheKey::Routing(uuid) => format!("routing.{uuid}"),
            CacheKey::Rule { id, version } => format!("rule.{id}.{version}"),
            CacheKey::Typology { id, version } => format!("typology.{id}.{version}"),
        };

        out.write_arg(value.as_bytes());
    }
}