Skip to content

Commit a4ef9d8

Browse files
authored
refactor: update module paths and documentation for FIFO cache (#60)
- Changed import paths in examples and tests to use the new `cachekit::policy::fifo::FifoCache` structure, enhancing clarity and consistency. - Updated `Cargo.toml` to remove the outdated documentation link. - Adjusted module documentation to reflect the addition of a release notes section, improving user awareness of changes. - Incremented the eviction policy count in the documentation to accurately represent the current implementation.
1 parent d17d93a commit a4ef9d8

11 files changed

Lines changed: 194 additions & 101 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ authors = ["Thomas Korrison <ferrite.db@gmail.com>"]
1111
license = "MIT OR Apache-2.0"
1212
description = "High-performance cache primitives with pluggable eviction policies (LRU, LFU, FIFO, 2Q, Clock-PRO, S3-FIFO) and optional metrics."
1313
homepage = "https://oxidizelabs.github.io/cachekit/"
14-
documentation = "https://docs.rs/cachekit"
1514
repository = "https://github.com/OxidizeLabs/cachekit"
1615
readme = "README.md"
1716
keywords = ["cache", "lru", "lfu", "eviction", "s3-fifo"]

examples/basic_fifo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cachekit::prelude::FifoCache;
1+
use cachekit::policy::fifo::FifoCache;
22
use cachekit::traits::CoreCache;
33

44
fn main() {

src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
//! │ │
3737
//! │ traits Trait hierarchy (ReadOnlyCache → CoreCache → …) │
3838
//! │ builder Unified CacheBuilder + Cache<K,V> wrapper │
39-
//! │ policy 17 eviction policies behind feature flags │
39+
//! │ policy 18 eviction policies behind feature flags │
4040
//! │ ds Arena, ring buffer, intrusive list, ghost list, … │
4141
//! │ store Storage backends (HashMap, slab, weighted) │
4242
//! │ metrics Hit/miss counters and snapshots (feature-gated) │
@@ -162,6 +162,11 @@
162162
//! return [`ConfigError`](error::ConfigError) for invalid parameters. Debug-only
163163
//! invariant checks produce [`InvariantError`](error::InvariantError).
164164
//!
165+
//! # Release Notes
166+
//!
167+
//! See the [changelog](https://github.com/OxidizeLabs/cachekit/blob/main/CHANGELOG.md)
168+
//! for a summary of changes in each published version.
169+
//!
165170
//! # Choosing a Policy
166171
//!
167172
//! ```text

src/policy/fifo.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,9 @@ where
736736
}
737737

738738
#[cfg(feature = "concurrency")]
739-
impl<K, V> ConcurrentCache for ConcurrentFifoCache<K, V>
739+
// SAFETY: ConcurrentFifoCache uses parking_lot RwLock internally for all
740+
// shared-state access, so concurrent operations are correctly synchronised.
741+
unsafe impl<K, V> ConcurrentCache for ConcurrentFifoCache<K, V>
740742
where
741743
K: Clone + Eq + Hash + Send + Sync,
742744
V: Send + Sync,
@@ -859,16 +861,14 @@ where
859861
None
860862
}
861863

862-
fn pop_oldest_batch(&mut self, count: usize) -> Vec<(K, V)> {
863-
let mut result = Vec::with_capacity(count.min(self.len()));
864+
fn pop_oldest_batch_into(&mut self, count: usize, out: &mut Vec<(K, V)>) {
865+
out.reserve(count.min(self.len()));
864866
for _ in 0..count {
865-
if let Some(entry) = self.pop_oldest() {
866-
result.push(entry);
867-
} else {
868-
break;
867+
match self.pop_oldest() {
868+
Some(entry) => out.push(entry),
869+
None => break,
869870
}
870871
}
871-
result
872872
}
873873

874874
fn age_rank(&self, key: &K) -> Option<usize> {
@@ -1513,8 +1513,8 @@ mod tests {
15131513
partial_cache.insert("d", 4);
15141514

15151515
// Remove 2 items
1516-
partial_cache.pop_oldest(); // Remove "a"
1517-
partial_cache.pop_oldest(); // Remove "b"
1516+
let _ = partial_cache.pop_oldest(); // Remove "a"
1517+
let _ = partial_cache.pop_oldest(); // Remove "b"
15181518
assert_eq!(partial_cache.len(), 2);
15191519

15201520
// Add 2 new items

src/policy/lfu.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2579,10 +2579,10 @@ mod tests {
25792579
assert_eq!(cache.len(), 2);
25802580

25812581
// Test pop_lfu operations
2582-
cache.pop_lfu();
2582+
let _ = cache.pop_lfu();
25832583
assert_eq!(cache.len(), 1);
25842584

2585-
cache.pop_lfu();
2585+
let _ = cache.pop_lfu();
25862586
assert_eq!(cache.len(), 0);
25872587

25882588
// Test pop_lfu on empty cache doesn't change length
@@ -2642,7 +2642,7 @@ mod tests {
26422642
cache.remove(&format!("key{}", capacity - 1));
26432643
assert_eq!(cache.capacity(), capacity);
26442644

2645-
cache.pop_lfu();
2645+
let _ = cache.pop_lfu();
26462646
assert_eq!(cache.capacity(), capacity);
26472647

26482648
cache.clear();
@@ -2673,7 +2673,7 @@ mod tests {
26732673
cache.remove(&format!("key{}", i % 10));
26742674
},
26752675
3 => {
2676-
cache.pop_lfu();
2676+
let _ = cache.pop_lfu();
26772677
},
26782678
_ => unreachable!(),
26792679
}
@@ -3113,7 +3113,7 @@ mod tests {
31133113
cache.remove(&format!("temp{}", i - 1));
31143114
},
31153115
3 => {
3116-
cache.pop_lfu();
3116+
let _ = cache.pop_lfu();
31173117
},
31183118
4 => {
31193119
cache.increment_frequency(&"key2".to_string());
@@ -3140,7 +3140,7 @@ mod tests {
31403140

31413141
// Test invariants after pop_lfu operations
31423142
while cache.len() > 0 {
3143-
cache.pop_lfu();
3143+
let _ = cache.pop_lfu();
31443144
verify_invariants(&mut cache);
31453145
}
31463146

src/policy/lru.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,8 +2155,8 @@ mod tests {
21552155
assert_eq!(cache.len(), 5);
21562156

21572157
// Simulate capacity reduction to 3 by removing 2 LRU items
2158-
cache.pop_lru(); // Remove 1
2159-
cache.pop_lru(); // Remove 2
2158+
let _ = cache.pop_lru(); // Remove 1
2159+
let _ = cache.pop_lru(); // Remove 2
21602160
assert_eq!(cache.len(), 3);
21612161

21622162
// Remaining items should be 3, 4, 5
@@ -3175,12 +3175,12 @@ mod tests {
31753175
assert_eq!(*new_tail_key, 2);
31763176

31773177
// Pop again
3178-
cache.pop_lru();
3178+
let _ = cache.pop_lru();
31793179
let (final_tail_key, _) = cache.peek_lru().unwrap();
31803180
assert_eq!(*final_tail_key, 3);
31813181

31823182
// Pop last item
3183-
cache.pop_lru();
3183+
let _ = cache.pop_lru();
31843184
assert!(cache.peek_lru().is_none());
31853185
assert_eq!(cache.len(), 0);
31863186
}
@@ -4258,7 +4258,7 @@ mod tests {
42584258
cache.insert(6, Arc::new(600));
42594259
verify_ranks(&cache);
42604260

4261-
cache.pop_lru();
4261+
let _ = cache.pop_lru();
42624262
verify_ranks(&cache);
42634263
}
42644264

@@ -6165,7 +6165,7 @@ mod tests {
61656165
cache.insert(3, Arc::new(3));
61666166

61676167
// Pop LRU
6168-
cache.pop_lru(); // Removes 1
6168+
let _ = cache.pop_lru(); // Removes 1
61696169

61706170
// Check recency rank of remaining items to force traversal
61716171
assert!(cache.recency_rank(&2).is_some());
@@ -6231,7 +6231,7 @@ mod tests {
62316231
cache.get(&2);
62326232

62336233
// Remove head (LRU)
6234-
cache.pop_lru(); // Should remove 0 (LRU)
6234+
let _ = cache.pop_lru(); // Should remove 0 (LRU)
62356235

62366236
// Remove tail (MRU)
62376237
cache.remove(&2); // 2 was MRU

src/policy/s3_fifo.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,9 @@ where
15471547
}
15481548

15491549
#[cfg(feature = "concurrency")]
1550-
impl<K, V> ConcurrentCache for ConcurrentS3FifoCache<K, V>
1550+
// SAFETY: ConcurrentS3FifoCache uses parking_lot RwLock internally for all
1551+
// shared-state access, so concurrent operations are correctly synchronised.
1552+
unsafe impl<K, V> ConcurrentCache for ConcurrentS3FifoCache<K, V>
15511553
where
15521554
K: Clone + Eq + Hash + Send + Sync,
15531555
V: Send + Sync,

src/prelude.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
pub use crate::ds::{
2-
ClockRing, FixedHistory, FrequencyBucketEntryMeta, FrequencyBuckets, FrequencyBucketsHandle,
3-
GhostList, IntrusiveList, KeyInterner, LazyMinHeap, ShardSelector, SlotArena, SlotId,
4-
};
1+
//! Convenience re-exports for the most common cachekit types.
2+
//!
3+
//! Import everything with:
4+
//!
5+
//! ```
6+
//! use cachekit::prelude::*;
7+
//! ```
8+
//!
9+
//! This gives you the core traits ([`CoreCache`], [`ReadOnlyCache`],
10+
//! [`MutableCache`]), the policy-specific traits, and the [`CacheBuilder`]
11+
//! entry point. Internal data structures and concrete policy types are
12+
//! available from their respective modules ([`ds`](crate::ds),
13+
//! [`policy`](crate::policy)).
514
6-
#[cfg(feature = "concurrency")]
7-
pub use crate::ds::{
8-
ConcurrentClockRing, ConcurrentIntrusiveList, ConcurrentSlotArena,
9-
ShardedFrequencyBucketEntryMeta, ShardedFrequencyBuckets, ShardedSlotArena, ShardedSlotId,
15+
pub use crate::builder::{Cache, CacheBuilder, CachePolicy};
16+
pub use crate::traits::{
17+
ConcurrentCache, CoreCache, FifoCacheTrait, LfuCacheTrait, LruCacheTrait, LrukCacheTrait,
18+
MutableCache, ReadOnlyCache,
1019
};
20+
1121
#[cfg(feature = "metrics")]
1222
pub use crate::metrics::snapshot::CacheMetricsSnapshot;
13-
#[cfg(feature = "policy-fifo")]
14-
pub use crate::policy::fifo::FifoCache;
15-
pub use crate::traits::{
16-
AsyncCacheFuture, CacheConfig, CacheFactory, CacheTier, CacheTierManager, ConcurrentCache,
17-
CoreCache, FifoCacheTrait, LfuCacheTrait, LruCacheTrait, LrukCacheTrait, MutableCache,
18-
ReadOnlyCache,
19-
};

0 commit comments

Comments
 (0)