Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ jobs:
- run: cargo check --all-targets --no-default-features --features sharded-lock
- run: cargo check --all-targets --features shuttle

msrv:
name: MSRV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: taiki-e/install-action@v2
with:
tool: cargo-msrv
# `cargo msrv verify` checks that the crate compiles with the
# `rust-version` declared in Cargo.toml. The default `cargo check` skips
# dev-dependencies, which may require a newer Rust than downstream needs.
- run: cargo msrv verify
- run: cargo msrv verify -- cargo check --features stats
- run: cargo msrv verify -- cargo check --no-default-features
- run: cargo msrv verify -- cargo check --no-default-features --features sharded-lock

test:
name: Tests
strategy:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quick_cache"
version = "0.6.21"
version = "0.7.0"
edition = "2021"
description = "Lightweight and high performance concurrent cache"
repository = "https://github.com/arthurprs/quick-cache"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Lightweight and high performance concurrent cache optimized for low cache overhe
* Scales well with the number of threads
* Atomic operations with `get_or_insert` and `get_value_or_guard` functions
* Atomic async operations with `get_or_insert_async` and `get_value_or_guard_async` functions
* Non-blocking `try_get`, `try_insert`, `try_remove`, and related methods that return an error instead of blocking: typically `Err(LockContention)`, or `Err((Key, Val))` for `try_insert`/`try_insert_with_lifecycle` so inputs are preserved
* Non-blocking methods that return immediately on lock contention.
* Closure-based `entry` API for atomic inspect-and-act patterns (keep, remove, replace)
* Supports item pinning
* Iteration and draining
Expand Down
2 changes: 0 additions & 2 deletions examples/eviction_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ struct EvictionListener(mpsc::Sender<(u64, u64)>);
impl Lifecycle<u64, u64> for EvictionListener {
type RequestState = ();

fn begin_request(&self) -> Self::RequestState {}

fn on_evict(&self, _state: &mut Self::RequestState, key: u64, val: u64) {
let _ = self.0.send((key, val));
}
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions fuzz/fuzz_targets/fuzz_sync_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ impl Weighter<u16, Value> for MyWeighter {
impl Lifecycle<u16, Value> for MyLifecycle {
type RequestState = Vec<(u16, Value)>;

fn begin_request(&self) -> Self::RequestState {
Default::default()
}

fn is_pinned(&self, _key: &u16, val: &Value) -> bool {
val.pinned
}
Expand Down Expand Up @@ -104,13 +100,15 @@ fn run(input: Input) {
match op {
Op::Insert(k, v, pinned) => {
// eprintln!("insert {k} {v}");
let evicted = cache.insert_with_lifecycle(
let mut evicted = Vec::new();
cache.insert_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
&mut evicted,
);
placeholders.remove(&k);
// if k is present it must have value v
Expand All @@ -121,15 +119,20 @@ fn run(input: Input) {
Op::Replace(k, v, pinned) => {
// eprintln!("replace {k} {v}");
placeholders.remove(&k);
if let Ok(evicted) = cache.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
false,
) {
let mut evicted = Vec::new();
if cache
.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
false,
&mut evicted,
)
.is_ok()
{
// if k is present it must have value v
let peek = cache.peek(&k);
assert!(peek.is_none() || peek.unwrap().original == v);
Expand All @@ -155,7 +158,8 @@ fn run(input: Input) {
current: v,
pinned,
};
if let Ok(evicted) = p.insert_with_lifecycle(value) {
let mut evicted = Vec::new();
if p.insert_with_lifecycle(value, &mut evicted).is_ok() {
let peek = cache.peek(&k);
assert!(peek.is_none() || peek.unwrap().original == v);
check_evicted(k, peek, evicted);
Expand Down
45 changes: 26 additions & 19 deletions fuzz/fuzz_targets/fuzz_unsync_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ impl Weighter<u16, Value> for MyWeighter {
impl Lifecycle<u16, Value> for MyLifecycle {
type RequestState = Vec<(u16, Value)>;

fn begin_request(&self) -> Self::RequestState {
Default::default()
}

fn is_pinned(&self, _key: &u16, val: &Value) -> bool {
val.pinned
}
Expand Down Expand Up @@ -99,13 +95,15 @@ fn run(input: Input) {
match op {
Op::Insert(k, v, pinned) => {
// eprintln!("insert {k} {v}");
let evicted = cache.insert_with_lifecycle(
let mut evicted = Vec::new();
cache.insert_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
&mut evicted,
);
// if k is present it must have value v
let peek = cache.peek(&k).copied();
Expand All @@ -125,15 +123,20 @@ fn run(input: Input) {
}
Op::Replace(k, v, pinned) => {
// eprintln!("replace {k} {v}");
if let Ok(evicted) = cache.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
false,
) {
let mut evicted = Vec::new();
if cache
.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned,
},
false,
&mut evicted,
)
.is_ok()
{
// if k is present it must have value v
let peek = cache.peek(&k).copied();
assert!(peek.is_none() || peek.unwrap().original == v);
Expand All @@ -146,11 +149,15 @@ fn run(input: Input) {
let (inserted, evicted) = match cache.get_ref_or_guard(&k) {
Ok(_) => (false, Vec::new()),
Err(g) => {
let evicted = g.insert_with_lifecycle(Value {
original: v,
current: v,
pinned,
});
let mut evicted = Vec::new();
g.insert_with_lifecycle(
Value {
original: v,
current: v,
pinned,
},
&mut evicted,
);
(true, evicted)
}
};
Expand Down
45 changes: 26 additions & 19 deletions fuzz/fuzz_targets/fuzz_unsync_cache_pinstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ impl Weighter<u16, Value> for MyWeighter {
impl Lifecycle<u16, Value> for MyLifecycle {
type RequestState = Vec<(u16, Value)>;

fn begin_request(&self) -> Self::RequestState {
Default::default()
}

fn is_pinned(&self, _key: &u16, val: &Value) -> bool {
let mut pinned = val.pinned.get();
if pinned.remaining != 0 {
Expand Down Expand Up @@ -114,13 +110,15 @@ fn run(input: Input) {
match op {
Op::Insert(k, v, pinned) => {
// eprintln!("insert {k} {v}");
let evicted = cache.insert_with_lifecycle(
let mut evicted = Vec::new();
cache.insert_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned: Cell::new(pinned),
},
&mut evicted,
);
// if k is present it must have value v
let peek = cache.peek(&k).cloned();
Expand All @@ -138,15 +136,20 @@ fn run(input: Input) {
}
Op::Replace(k, v, pinned) => {
// eprintln!("replace {k} {v}");
if let Ok(evicted) = cache.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned: Cell::new(pinned),
},
false,
) {
let mut evicted = Vec::new();
if cache
.replace_with_lifecycle(
k,
Value {
original: v,
current: v,
pinned: Cell::new(pinned),
},
false,
&mut evicted,
)
.is_ok()
{
// if k is present it must have value v
let peek = cache.peek(&k).cloned();
assert!(peek.is_none() || peek.as_ref().unwrap().original == v);
Expand All @@ -159,11 +162,15 @@ fn run(input: Input) {
let (inserted, evicted) = match cache.get_ref_or_guard(&k) {
Ok(_) => (false, Vec::new()),
Err(g) => {
let evicted = g.insert_with_lifecycle(Value {
original: v,
current: v,
pinned: Cell::new(pinned),
});
let mut evicted = Vec::new();
g.insert_with_lifecycle(
Value {
original: v,
current: v,
pinned: Cell::new(pinned),
},
&mut evicted,
);
(true, evicted)
}
};
Expand Down
Loading
Loading