basic_enum!(pubPurgeOrder;"How should a cache determine what to purge": Oldest=>"Purge the oldest entries first",LeastUsed=>"Purge the least accessed entries first",OldestUsed=>"Purge the oldest accessed entries first");
default!(PurgeOrder: Self::LeastUsed);
@ -64,22 +80,59 @@ struct Memory(Bytes);
#[derive(Debug)]
pubstructCacheEntry//<K: Key> // `K` is the key in `entries`.
{
id: Uuid,
tm_accessed: RwLock<DateTime<Timezone>>,// Can be mutated when read, so must be mutable by the reader, hence the `RwLock`.
tm_created: DateTime<Timezone>,
accesses: AtomicUsize,// Can be mutated when read, hence the atomic.
memory: Option<Memory>,
// Pathname is computed from `key`.
// Pathname is computed from `id`.
}
/// A byte-stream cache. Caches both to memory and also writes entries to disk.
/// A byte-stream cache of data. Caches both to memory and also writes entries to disk.
#[derive(Debug)]
pubstructByteCache<K: Key>
{
/// How the cache should operate
// Config is big, box it.
cfg: Box<Config>,
/// Frozen entries.
entries: HashMap<K,CacheEntry>,
entries: RwLock<HashMap<K,CacheEntry>>,
///// Non-complete entries are completed with async semantics.
///// Moving them to `entries` is completed with sync semantics.
// TODO: Is this right at all? eh...
// FUCK This shit, don't store it here, do it somewhere fucking else FUCK.