https://github.com/melonask/moka-skills
Rust Concurrent Cache Skill
https://github.com/melonask/moka-skills
Last synced: 20 days ago
JSON representation
Rust Concurrent Cache Skill
- Host: GitHub
- URL: https://github.com/melonask/moka-skills
- Owner: melonask
- Created: 2026-04-20T21:23:29.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2026-04-22T03:27:02.000Z (2 months ago)
- Last Synced: 2026-04-22T05:32:02.386Z (2 months ago)
- Size: 15.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# moka-skills
A comprehensive AI skill for building high-performance caching solutions using the [Moka](https://github.com/moka-rs/moka) Rust library. Moka is a fast, concurrent, in-memory cache library inspired by Java's Caffeine, providing near-optimal hit ratios through the TinyLFU eviction policy.
## Overview
This skill enables an LLM to accurately use and develop solutions based on the Moka caching library. It covers the full API surface of Moka v0.12, including synchronous and asynchronous cache types, eviction policies, expiration strategies, and advanced features — all with concrete Rust code examples.
The skill is structured as a single `SKILL.md` file that serves as a complete reference and coding guide. It follows progressive disclosure principles: the metadata (name + description) is always in context for triggering, and the full instructions load when the skill is invoked.
## Installation
```bash
npx skills add melonask/moka-skills
```
## What This Skill Covers
### Cache Types
- **`sync::Cache`** — Thread-safe synchronous cache for general-purpose use
- **`sync::SegmentedCache`** — Multi-segment sync cache for high-contention workloads
- **`future::Cache`** — Async-aware cache for tokio, async-std, and actix-rt
### Eviction Policies
- **TinyLFU** (default) — Near-optimal hit ratios combining LFU admission with LRU eviction
- **LRU** — Simple least-recently-used eviction for recency-biased workloads
- **Size-aware eviction** — Bounded by total weighted size via custom `weigher` closures
### Expiration
- **TTL** (time-to-live) — Max age from creation/update
- **TTI** (time-to-idle) — Max age since last access
- **Per-entry custom expiry** — Fine-grained control via the `Expiry` trait (variable TTL per key/value)
### Advanced Features
- **Atomic get-or-initialize** — `get_with`, `try_get_with`, `get_with_if`, `optionally_get_with`
- **Entry API** — Fine-grained insertion control via `entry()` / `entry_by_ref()` selectors
- **Eviction listeners** — Sync and async callbacks on entry removal (`Expired`, `Explicit`, `Replaced`, `Size`)
- **Invalidation** — Single, bulk, and predicate-based (`invalidate_entries_if`)
- **Borrowed-key lookups** — Zero-allocation lookups via the `Equivalent` trait
- **Custom hashers** — Support for `ahash`, `dashmap`, or any `BuildHasher`
- **Housekeeper model** — No background threads; maintenance runs on caller threads
## File Structure
```
moka/
└── SKILL.md # Complete skill definition (~500 lines)
├── YAML frontmatter (name, description — triggering metadata)
└── Markdown body (instructions, API reference, code examples)
```
## Quick Start Example
```toml
# Cargo.toml
[dependencies]
moka = { version = "0.12", features = ["sync"] }
```
```rust
use moka::sync::Cache;
fn main() {
let cache: Cache = Cache::new(10_000);
// Atomic get-or-initialize with concurrent deduplication
let value = cache.get_with("key".to_string(), || {
expensive_database_lookup()
});
println!("Got: {}", value);
}
```
## Trigger Phrases
The skill triggers automatically when the user asks about:
- In-memory caching in Rust
- Concurrent or thread-safe caches
- TTL, TTI, or expiration in caching
- Cache eviction policies (TinyLFU, LRU)
- Async caches with tokio or async-std
- The `moka` crate by name
- Any request to speed up a Rust application with caching
## Requirements
- **Moka crate**: v0.12.x
- **Rust MSRV**: 1.71.1+
- **Rust Edition**: 2021
- At least one of `sync` or `future` feature flags must be enabled
## License
This skill document is provided for educational and development purposes. The Moka library is licensed under MIT OR Apache-2.0.