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
26
27
28
use bytes::Bytes;

/// A record in a cache. This is designed to represent values in a simple
/// key-value store, and so it has minimal fields. The `uri` field is the
/// key, and the `data` field is the value. An extra `meta` field is included
/// for additional information that may be useful, like timestamps or other
/// bits that might not make sense to store in the `data` field.
///
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct CacheRecord {
    /// The URI of the record
    pub uri: String,
    /// The main data of the record
    pub data: Bytes,
    /// Any additional metadata
    pub meta: Bytes,
}

impl CacheRecord {
    /// Create a new cache record
    pub fn new(uri: impl Into<String>, data: impl Into<Bytes>) -> Self {
        Self {
            uri: uri.into(),
            data: data.into(),
            ..Default::default()
        }
    }
}