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

Add moka::dash::Cache, which uses dash::DashMap as the internal storage #99

Merged
merged 4 commits into from
Mar 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
command: |
docker run --security-opt seccomp=unconfined -v "${PWD}:/volume" xd009642/tarpaulin \
cargo tarpaulin -v \
--features future \
--features 'future, dash' \
--ciserver circle-ci \
--coveralls ${COVERALLS_TOKEN} \
--timeout 600 \
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,22 @@ jobs:
with:
command: build

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

- name: Run tests (future feature)
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != '1.45.2' }}
with:
command: test
args: --features future

- name: Run tests (release, no features)
- name: Run tests (dash feature)
uses: actions-rs/cargo@v1
if: ${{ matrix.rust != '1.45.2' }}
with:
command: test
args: --release
args: --features dash
7 changes: 7 additions & 0 deletions .github/workflows/LinuxCrossCompileTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,10 @@ jobs:
use-cross: true
command: test
args: --release --features future --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}

- name: Run tests (dash feature)
uses: actions-rs/cargo@v1
with:
use-cross: true
command: test
args: --release --features dash --target ${{ matrix.platform.target }} ${{ matrix.platform.cargo-opts }}
12 changes: 6 additions & 6 deletions .github/workflows/Skeptic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ jobs:
env:
RUSTFLAGS: '--cfg skeptic'

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

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

- name: Run UI tests (future, trybuild)
- name: Run UI tests (future and dash features, trybuild)
uses: actions-rs/cargo@v1
if: ${{ matrix.rust == 'stable' }}
with:
command: test
args: ui_trybuild --release --features future
args: ui_trybuild --release --features 'future, dash'
env:
RUSTFLAGS: '--cfg trybuild'
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"rust-analyzer.cargo.features": ["future", "unstable-debug-counters"],
"rust-analyzer.cargo.features": ["future", "dash", "unstable-debug-counters"],
"rust-analyzer.server.extraEnv": {
"CARGO_TARGET_DIR": "target/ra"
},
Expand All @@ -13,6 +13,7 @@
"clippy",
"compat",
"cpus",
"dashmap",
"deqs",
"Deque",
"Deques",
Expand All @@ -22,6 +23,7 @@
"getrandom",
"Hasher",
"Kawano",
"mapref",
"Moka",
"mpsc",
"MSRV",
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Version 0.8.0

### Added

- Add a synchronous cache `moka::dash::Cache`, which uses `dash::DashMap` as
the internal storage. ([#99][gh-pull-0099])

### Changed

- Update the minimum depending version of crossbeam-channel from v0.5.2 to v0.5.4.
Expand Down Expand Up @@ -245,6 +250,7 @@ The minimum supported Rust version (MSRV) is now 1.51.0 (2021-03-25).
[gh-issue-0031]: https://github.com/moka-rs/moka/issues/31/

[gh-pull-0100]: https://github.com/moka-rs/moka/pull/100/
[gh-pull-0099]: https://github.com/moka-rs/moka/pull/99/
[gh-pull-0086]: https://github.com/moka-rs/moka/pull/86/
[gh-pull-0084]: https://github.com/moka-rs/moka/pull/84/
[gh-pull-0083]: https://github.com/moka-rs/moka/pull/83/
Expand Down
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ default = ["atomic64"]
# Enable this feature to use `moka::future::Cache`.
future = ["async-io", "async-lock", "futures-util"]

# Enable this feature to use `moka::dash::Cache`.
dash = ["dashmap"]

# 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 @@ -47,7 +50,10 @@ thiserror = "1.0"
triomphe = "0.1"
uuid = { version = "0.8", features = ["v4"] }

# Optional dependencies
# Optional dependencies (dashmap)
dashmap = { version = "5.2", optional = true }

# Optional dependencies (future)
async-io = { version = "1.4", optional = true }
async-lock = { version = "2.4", optional = true }
futures-util = { version = "0.3", optional = true }
Expand All @@ -68,8 +74,8 @@ skeptic = "0.13"

# https://docs.rs/about/metadata
[package.metadata.docs.rs]
# Build the doc with "future" feature enabled.
features = ["future"]
# Build the doc with some features enabled.
features = ["future", "dash"]

# ----------------------------------
# RUSTSEC, etc.
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ This crate's minimum supported Rust versions (MSRV) are the followings:
| no feature | | Rust 1.51.0 |
| `atomic64` | yes | Rust 1.51.0 |
| `future` | | Rust 1.51.0 |
| `dash` | | Rust 1.51.0 |

If only the default features are enabled, MSRV will be updated conservatively. When
using other features, like `future`, MSRV might be updated more frequently, up to the
Expand Down Expand Up @@ -470,8 +471,8 @@ $ RUSTFLAGS='--cfg skeptic --cfg trybuild' cargo test \
- [ ] API stabilization. (Smaller core cache API, shorter names for frequently
used methods)
- e.g.
- `get_or_insert_with(K, F)` → `get(K, F)`
- `get_or_try_insert_with(K, F)` → `try_get(K, F)`
- `get_or_insert_with(K, F)` → `get_with(K, F)`
- `get_or_try_insert_with(K, F)` → `try_get_with(K, F)`
- `get(&Q)` → `get_if_present(&Q)`
- `blocking_insert(K, V)` → `blocking().insert(K, V)`
- `time_to_live()` → `config().time_to_live()`
Expand Down
20 changes: 20 additions & 0 deletions src/dash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Provides a thread-safe, concurrent cache implementation built upon
//! [`dashmap::DashMap`][dashmap].
//!
//! To use this module, enable a crate feature called "dash".
//!
//! [dashmap]: https://docs.rs/dashmap/*/dashmap/struct.DashMap.html

mod base_cache;
mod builder;
mod cache;
// mod value_initializer;

pub use builder::CacheBuilder;
pub use cache::Cache;

/// Provides extra methods that will be useful for testing.
pub trait ConcurrentCacheExt<K, V> {
/// Performs any pending maintenance operations needed by the cache.
fn sync(&self);
}
Loading