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");
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);
default!(PurgeOrder: Self::LeastUsed);
@ -64,22 +80,59 @@ struct Memory(Bytes);
#[derive(Debug)]
#[derive(Debug)]
pubstructCacheEntry//<K: Key> // `K` is the key in `entries`.
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_accessed: RwLock<DateTime<Timezone>>,// Can be mutated when read, so must be mutable by the reader, hence the `RwLock`.
tm_created: DateTime<Timezone>,
tm_created: DateTime<Timezone>,
accesses: AtomicUsize,// Can be mutated when read, hence the atomic.
accesses: AtomicUsize,// Can be mutated when read, hence the atomic.
memory: Option<Memory>,
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)]
#[derive(Debug)]
pubstructByteCache<K: Key>
pubstructByteCache<K: Key>
{
{
/// How the cache should operate
// Config is big, box it.
// Config is big, box it.
cfg: Box<Config>,
cfg: Box<Config>,
/// Frozen entries.
/// 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.