Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge branch next into master (v0.9.0) #161

Merged
merged 56 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
952af01
bump scheduled-thread-pool
Milo123459 May 28, 2022
cb9bc3c
apply visibility changes
Milo123459 May 28, 2022
3410c04
fixes?
Milo123459 May 28, 2022
6c11610
Merge pull request #141 from Milo123459/remove-deps
tatsuya6502 May 28, 2022
97d4759
Merge branch 'master' into gh141-optout-sync
tatsuya6502 May 29, 2022
264f048
Introduce a new crate feature called `sync`
tatsuya6502 May 29, 2022
abdace2
Fix a CI job
tatsuya6502 May 29, 2022
2ebcc66
Merge pull request #143 from moka-rs/gh141-optout-sync
tatsuya6502 May 29, 2022
a77a9e3
Merge branch 'master' into next
tatsuya6502 May 29, 2022
3f28855
Support notification on eviction
tatsuya6502 May 30, 2022
aecfef1
Support notification on eviction
tatsuya6502 May 30, 2022
b4e0171
Fix a Clippy warning
tatsuya6502 May 31, 2022
1727b78
Support notification on eviction
tatsuya6502 May 31, 2022
31d6874
Support notification on eviction
tatsuya6502 May 31, 2022
14ba86a
Support notification on eviction
tatsuya6502 May 31, 2022
7fa072b
Support notification on eviction
tatsuya6502 May 31, 2022
fa991fa
Support notification on eviction
tatsuya6502 May 31, 2022
ea67182
Support notification on eviction
tatsuya6502 Jun 1, 2022
5b3aa78
Support notification on eviction
tatsuya6502 Jun 1, 2022
d8567c9
Support notification on eviction
tatsuya6502 Jun 12, 2022
8adca0f
Support notification on eviction
tatsuya6502 Jun 12, 2022
b39d669
Support notification on eviction
tatsuya6502 Jun 13, 2022
59ca134
Raise the minimal version of Triomphe crate from v0.1 to v0.1.3
tatsuya6502 Jun 14, 2022
090844e
Support notification on eviction
tatsuya6502 Jun 14, 2022
2ae237c
Merge branch 'master' into next
tatsuya6502 Jun 18, 2022
5e3a3cd
Merge branch 'next' into eviction-listener
tatsuya6502 Jun 18, 2022
1462700
Support notification on eviction
tatsuya6502 Jun 20, 2022
fac2a00
Support notification on eviction
tatsuya6502 Jun 20, 2022
e8f75ac
Support notification on eviction
tatsuya6502 Jun 21, 2022
6cf464a
Support notification on eviction
tatsuya6502 Jun 21, 2022
9b65faa
Support notification on eviction
tatsuya6502 Jun 21, 2022
b49f5e9
Support notification on eviction
tatsuya6502 Jun 26, 2022
81d36ff
Bump the version to v0.9.0
tatsuya6502 Jun 26, 2022
8ec7c2b
Support notification on eviction
tatsuya6502 Jun 26, 2022
a6fbf2a
Support notification on eviction
tatsuya6502 Jun 26, 2022
cd885b6
Merge branch 'master' into next
tatsuya6502 Jun 28, 2022
84f52ec
Merge branch 'master' into next (continued)
tatsuya6502 Jun 28, 2022
3b40d96
Support notification on eviction
tatsuya6502 Jun 28, 2022
f02d9c6
Merge branch 'next' into eviction-listener
tatsuya6502 Jun 28, 2022
db3ba66
Merge branch 'master' into fix-ci-errors-2022-07-next-br
tatsuya6502 Jul 2, 2022
09b986c
Update the trybuild expectations for Rust 1.62
tatsuya6502 Jul 2, 2022
7911deb
Add `logging` feature to enable optional `log` crate dependency
tatsuya6502 Jul 2, 2022
2460cf6
Merge pull request #159 from moka-rs/add-logger
tatsuya6502 Jul 2, 2022
e49f0fe
Merge branch 'next' into eviction-listener
tatsuya6502 Jul 2, 2022
b97f622
Support notification on eviction
tatsuya6502 Jul 2, 2022
cf758d5
Fix Clippy warning
tatsuya6502 Jul 2, 2022
b206dbc
Support notification on eviction
tatsuya6502 Jul 3, 2022
e207c38
Support notification on eviction
tatsuya6502 Jul 3, 2022
5e0b978
Support notification on eviction
tatsuya6502 Jul 4, 2022
6a5b974
Support notification on eviction
tatsuya6502 Jul 4, 2022
823f7e3
Support notification on eviction
tatsuya6502 Jul 4, 2022
fc8d7ee
Support notification on eviction
tatsuya6502 Jul 4, 2022
2aff444
Support notification on eviction
tatsuya6502 Jul 4, 2022
317b0ab
Support notification on eviction
tatsuya6502 Jul 4, 2022
02fe6c8
Merge pull request #145 from moka-rs/eviction-listener
tatsuya6502 Jul 4, 2022
a158e82
Update the change log (v0.9.0)
tatsuya6502 Jul 4, 2022
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
--env RUSTFLAGS='--cfg circleci' \
xd009642/tarpaulin \
cargo tarpaulin -v \
--features 'future, dash' \
--features 'sync, future, dash' \
--ciserver circle-ci \
--coveralls ${COVERALLS_TOKEN} \
--timeout 600 \
Expand Down
23 changes: 15 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,32 @@ jobs:
command: tree
args: --features 'future, dash'

- name: Build (no features)
- name: Run tests (debug, sync feature)
uses: actions-rs/cargo@v1
with:
command: build
command: test
args: --features sync

- name: Run tests (release, sync feature)
uses: actions-rs/cargo@v1
with:
command: test
args: --release --features sync

- name: Run tests (release, no features)
- name: Run tests (future feature, but no sync feature)
uses: actions-rs/cargo@v1
with:
command: test
args: --release
args: --no-default-features --features 'future, atomic64, quanta'

- name: Run tests (future feature)
- name: Run tests (future, sync and logging features)
uses: actions-rs/cargo@v1
with:
command: test
args: --features future
args: --features 'future, sync, logging'

- name: Run tests (dash feature)
- name: Run tests (dash feature, but no sync feature)
uses: actions-rs/cargo@v1
with:
command: test
args: --features dash
args: --no-default-features --features 'dash, atomic64, quanta'
20 changes: 13 additions & 7 deletions .github/workflows/CIQuantaDisabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,31 @@ jobs:
cargo update -p native-tls --precise 0.2.8
cargo update -p async-global-executor --precise 2.0.4

- name: Build (no quanta feature)
- name: Run tests (debug, but no quanta feature)
uses: actions-rs/cargo@v1
with:
command: build
args: --no-default-features --features atomic64
command: test
args: --no-default-features --features 'sync, atomic64'

- name: Run tests (release, no quanta feature)
- name: Run tests (release, but no quanta feature)
uses: actions-rs/cargo@v1
with:
command: test
args: --release --no-default-features --features atomic64
args: --release --no-default-features --features 'sync, atomic64'

- name: Run tests (future feature, but no quanta feature)
- name: Run tests (future feature, but no quanta and sync features)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features 'future, atomic64'

- name: Run tests (dash feature, but no quanta feature)
- name: Run tests (future, sync and logging features, but no quanta feature)
uses: actions-rs/cargo@v1
with:
command: test
args: --no-default-features --features 'sync, future, atomic64, logging'

- name: Run tests (dash feature, but no quanta and sync features)
uses: actions-rs/cargo@v1
with:
command: test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/LinuxCrossCompileTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ jobs:
with:
command: clean

- name: Run tests (no features)
- name: Run tests (sync feature)
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --release --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
args: --release --features sync --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}

- name: Run tests (future feature)
uses: actions-rs/cargo@v1
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/Skeptic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: test
args: --release --features 'future, dash'
args: --release --features 'sync, future, dash'
env:
RUSTFLAGS: '--cfg skeptic'

- name: Run tests (future and dash, without atomic64)
- name: Run tests (sync, future and dash, without atomic64 and quanta)
uses: actions-rs/cargo@v1
with:
command: test
args: --release --no-default-features --features 'future, dash'
args: --release --no-default-features --features 'sync, future, dash'
env:
RUSTFLAGS: '--cfg skeptic'

- name: Run compile error tests (future and dash features, trybuild)
- name: Run compile error tests (sync, future and dash features, trybuild)
uses: actions-rs/cargo@v1
if: ${{ matrix.rust == 'stable' }}
with:
command: test
args: ui_trybuild --release --features 'future, dash'
args: ui_trybuild --release --features 'sync, future, dash'
env:
RUSTFLAGS: '--cfg trybuild'
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"rust-analyzer.cargo.features": ["future", "dash", "unstable-debug-counters"],
"rust-analyzer.cargo.features": ["future", "dash", "logging", "unstable-debug-counters"],
"rust-analyzer.server.extraEnv": {
"CARGO_TARGET_DIR": "target/ra"
},
"editor.rulers": [85],
"cSpell.words": [
"aarch",
"actix",
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# Moka Cache — Change Log

## Version 0.9.0

### Added

- Add support for eviction listener to the following caches ([#145][gh-pull-0145]).
Eviction listener is a callback function that will be called when an entry is
removed from the cache.
- `sync::Cache`
- `sync::SegmentedCache`
- `future::Cache`
- Add a crate feature `sync` for enabling and disabling `sync` caches.
([#143][gh-pull-0143])
- This feature is enabled by default.
- When using experimental `dash` cache, opting out of `sync` will reduce the
number of dependencies.
- Add a crate feature `logging` to enable optional log crate dependency.
([#159][gh-pull-0159])
- Currently log will be emitted only when an eviction listener has panicked.


## Version 0.8.6

### Fixed
Expand Down Expand Up @@ -392,6 +412,9 @@ The minimum supported Rust version (MSRV) is now 1.51.0 (2021-03-25).
[gh-issue-0034]: https://github.com/moka-rs/moka/issues/34/
[gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/

[gh-pull-0159]: https://github.com/moka-rs/moka/pull/159/
[gh-pull-0145]: https://github.com/moka-rs/moka/pull/145/
[gh-pull-0143]: https://github.com/moka-rs/moka/pull/143/
[gh-pull-0138]: https://github.com/moka-rs/moka/pull/138/
[gh-pull-0137]: https://github.com/moka-rs/moka/pull/137/
[gh-pull-0133]: https://github.com/moka-rs/moka/pull/133/
Expand Down
42 changes: 28 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "moka"
version = "0.8.6"
version = "0.9.0"
edition = "2018"
rust-version = "1.51"

Expand All @@ -16,16 +16,25 @@ exclude = [".circleci", ".devcontainer", ".github", ".gitpod.yml", ".vscode"]
build = "build.rs"

[features]
default = ["atomic64", "quanta"]
default = ["sync", "atomic64", "quanta"]

# This feature is enabled by default. Disable it when you do not need
# `moka::sync::{Cache, SegmentedCache}`
sync = ["crossbeam-epoch", "thiserror", "uuid"]

# Enable this feature to use `moka::future::Cache`.
future = ["async-io", "async-lock", "futures-util"]
future = ["crossbeam-epoch", "thiserror", "uuid", "async-io", "async-lock", "futures-util"]

# Enable this feature to use **experimental** `moka::dash::Cache`.
# Please note that the APIs for this feature will be frequently changed in next
# few releases.
dash = ["dashmap"]

# Enable this feature to activate optional logging from caches.
# Currently cache will emit log only when it encounters a panic in user provided
# callback closure.
logging = ["log"]

# This feature is enabled by default. Disable it when the target platform does not
# support `std::sync::atomic::AtomicU64`. (e.g. `armv5te-unknown-linux-musleabi`
# or `mips-unknown-linux-musl`)
Expand All @@ -43,23 +52,23 @@ crossbeam-utils = "0.8"
num_cpus = "1.13"
once_cell = "1.7"
parking_lot = "0.12"
scheduled-thread-pool = "0.2.5"
scheduled-thread-pool = "0.2.6"
smallvec = "1.8"
tagptr = "0.2"
thiserror = "1.0"
uuid = { version = "1.1", features = ["v4"] }

# Although v0.8.2 is not the current version (v0.9.x), we will keep using it until
# we perform enough tests to get conformable with memory safety.
# See: https://github.com/moka-rs/moka/issues/34
crossbeam-epoch = "0.8.2"

# Opt-out serde and stable_deref_trait features
# https://github.com/Manishearth/triomphe/pull/5
triomphe = { version = "0.1", default-features = false }
triomphe = { version = "0.1.3", default-features = false }

# Optional dependencies (quanta, enabled by default)
# Optional dependencies (enabled by default)
quanta = { version = "0.10.0", optional = true }
thiserror = { version = "1.0", optional = true }
uuid = { version = "1.1", features = ["v4"], optional = true }

# Although v0.8.2 is not the current version (v0.9.x), we will keep using it until
# we perform enough tests to get conformable with memory safety.
# See: https://github.com/moka-rs/moka/issues/34
crossbeam-epoch = { version = "0.8.2", optional = true }

# Optional dependencies (dashmap)
dashmap = { version = "5.2", optional = true }
Expand All @@ -69,13 +78,18 @@ async-io = { version = "1.4", optional = true }
async-lock = { version = "2.4", optional = true }
futures-util = { version = "0.3", optional = true }

# Optional dependencies (logging)
log = { version = "0.4", optional = true }

[dev-dependencies]
actix-rt = { version = "2.7", default-features = false }
anyhow = "1.0"
async-std = { version = "1.11", features = ["attributes"] }
env_logger = "0.9"
getrandom = "0.2"
reqwest = "0.11.11"
skeptic = "0.13"
tokio = { version = "1.19", features = ["rt-multi-thread", "macros", "sync", "time" ] }
tokio = { version = "1.19", features = ["fs", "macros", "rt-multi-thread", "sync", "time" ] }

[target.'cfg(trybuild)'.dev-dependencies]
trybuild = "1.0"
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ algorithm to determine which entries to evict when the capacity is exceeded.
- Supports expiration policies:
- Time to live
- Time to idle
- Supports eviction listener, a callback function that will be called when an entry
is removed from the cache.


[tiny-lfu]: https://github.com/moka-rs/moka/wiki#admission-and-eviction-policies

Expand Down Expand Up @@ -528,20 +531,23 @@ $ cargo +nightly -Z unstable-options --config 'build.rustdocflags="--cfg docsrs"
## Road Map

- [x] `async` optimized caches. (`v0.2.0`)
- [x] Size-aware eviction. (`v0.7.0` via
[#24](https://github.com/moka-rs/moka/pull/24))
- [X] API stabilization. (Smaller core cache API, shorter names for frequently
used methods) (`v0.8.0` via [#105](https://github.com/moka-rs/moka/pull/105))
- [x] Size-aware eviction. (`v0.7.0` via [#24][gh-pull-024])
- [x] API stabilization. (Smaller core cache API, shorter names for frequently
used methods) (`v0.8.0` via [#105][gh-pull-105])
- e.g.
- `get_or_insert_with(K, F)` → `get_with(K, F)`
- `get_or_try_insert_with(K, F)` → `try_get_with(K, F)`
- `blocking_insert(K, V)` → `blocking().insert(K, V)`
- `time_to_live()` → `policy().time_to_live()`
- [ ] Notifications on eviction, etc.
- [x] Notifications on eviction. (`v0.9.0` via [#145][gh-pull-145])
- [ ] Cache statistics. (Hit rate, etc.)
- [ ] Upgrade TinyLFU to Window-TinyLFU. ([details][tiny-lfu])
- [ ] The variable (per-entry) expiration, using a hierarchical timer wheel.

[gh-pull-024]: https://github.com/moka-rs/moka/pull/24
[gh-pull-105]: https://github.com/moka-rs/moka/pull/105
[gh-pull-145]: https://github.com/moka-rs/moka/pull/145


## About the Name

Expand Down
8 changes: 4 additions & 4 deletions src/cht/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ impl<K, V, S> HashMap<K, V, S> {
}
}

pub(crate) fn actual_num_segments(&self) -> usize {
self.segments.len()
}

/// Returns the number of elements in the map.
///
/// # Safety
Expand Down Expand Up @@ -560,10 +564,6 @@ impl<K: Hash + Eq, V, S: BuildHasher> HashMap<K, V, S> {
{
bucket::hash(&self.build_hasher, key)
}

pub(crate) fn actual_num_segments(&self) -> usize {
self.segments.len()
}
}

impl<K, V, S> Drop for HashMap<K, V, S> {
Expand Down
4 changes: 2 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::convert::TryInto;

// #[cfg(any(feature = "sync", feature = "future", feature = "dash"))]
#[cfg(any(feature = "sync", feature = "future", feature = "dash"))]
pub(crate) mod concurrent;

// #[cfg(any(feature = "sync", feature = "future"))]
#[cfg(any(feature = "sync", feature = "future"))]
pub(crate) mod error;

pub(crate) mod builder_utils;
Expand Down
4 changes: 2 additions & 2 deletions src/common/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ impl<K> KeyDate<K> {
&self.key
}

// #[cfg(any(feature = "sync", feature = "future"))]
#[cfg(any(feature = "sync", feature = "future"))]
pub(crate) fn last_modified(&self) -> Option<Instant> {
self.entry_info.last_modified()
}

// #[cfg(any(feature = "sync", feature = "future"))]
#[cfg(any(feature = "sync", feature = "future"))]
pub(crate) fn is_dirty(&self) -> bool {
self.entry_info.is_dirty()
}
Expand Down
12 changes: 8 additions & 4 deletions src/common/concurrent/thread_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ use std::{collections::HashMap, sync::Arc};

static REGISTRY: Lazy<ThreadPoolRegistry> = Lazy::new(ThreadPoolRegistry::default);

#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
// #[cfg_attr(any(feature = "sync", feature = "future"), derive(Debug))]
#[derive(Clone, Copy, Hash, PartialEq, Eq)]
#[cfg_attr(any(feature = "sync", feature = "future"), derive(Debug))]
pub(crate) enum PoolName {
Housekeeper,
// #[cfg(any(feature = "sync", feature = "future"))]
#[cfg(any(feature = "sync", feature = "future"))]
Invalidator,
#[cfg(any(feature = "sync", feature = "future"))]
RemovalNotifier,
}

impl PoolName {
fn thread_name_template(&self) -> &'static str {
match self {
PoolName::Housekeeper => "moka-housekeeper-{}",
// #[cfg(any(feature = "sync", feature = "future"))]
#[cfg(any(feature = "sync", feature = "future"))]
PoolName::Invalidator => "moka-invalidator-{}",
#[cfg(any(feature = "sync", feature = "future"))]
PoolName::RemovalNotifier => "moka-notifier-{}",
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl<T> Deque<T> {
self.region
}

// #[cfg(any(test, feature = "sync", feature = "future"))]
#[cfg(any(test, feature = "sync", feature = "future"))]
pub(crate) fn len(&self) -> usize {
self.len
}
Expand Down
Loading