展示 HN:Cachekit – Rust 中高性能缓存策略库
Show HN: Cachekit – High performance caching policies library in Rust

原始链接: https://github.com/OxidizeLabs/cachekit

CacheKit 是一个 Rust 库,旨在为系统编程和微服务等应用构建高性能缓存系统。它提供了一套工具,包括优化的缓存*替换策略*(FIFO、LRU、LRU-K 等)和*分层缓存原语*,用于创建分层缓存策略。 主要特性包括可选的指标收集器集成(如 Prometheus)和强大的基准测试工具,用于性能评估。CacheKit 优先考虑模块化、符合 Rust 习惯的 API,并具有 `no_std` 兼容性,从而可以对缓存行为进行细粒度控制。 它支持内存中和复合缓存后端。 详尽的文档详细介绍了架构、已实现的策略、数据结构和发布流程,使其成为需要可定制缓存的性能关键应用的文档完善且易于维护的解决方案。 您可以通过提供的 git 依赖项通过 `cargo.toml` 将其添加到您的项目中。

## Cachekit:新的 Rust 缓存库 一个名为 Cachekit 的新 Rust 库,专为高性能缓存策略设计,最近在 Hacker News 上分享。该库可在 GitHub 上找到 ([github.com/oxidizelabs](https://github.com/oxidizelabs))。 讨论很快转向代码风格,一位用户指出可能偏离官方 Rust API 命名约定(具体为 `LRUKCache` 与 `LrukCache`)。开发者承认了错误。 其他评论者要求将 Cachekit 与现有的 Rust 缓存解决方案(如 Foyer 和 quick-cache)进行基准测试,强调了合理的默认值和易于配置的内存限制的重要性。有人提出了关于文档中一个示例的问题,质疑所使用的容量值。最后,一位用户表达了对 Rust 中命名参数的渴望,以提高 IDE 之外的代码可读性。
相关文章

原文

CI Crates.io Docs MSRV License: MIT License: Apache-2.0

High-performance cache policies and tiered caching primitives for Rust systems with optional metrics and benchmarks.

CacheKit is a Rust library that provides:

  • High-performance cache replacement policies (e.g., FIFO, LRU, LRU-K).
  • Tiered caching primitives to build layered caching strategies.
  • Optional metrics and benchmark harnesses.
  • A modular API suitable for embedding in systems where control over caching behavior is critical.

This crate is designed for systems programming, microservices, and performance-critical applications.

  • Policy implementations optimized for performance and predictability.
  • Backends that support both in-memory and composite cache strategies.
  • Optional integration with metrics collectors (e.g., Prometheus/metrics crates).
  • Benchmarks to compare policy performance under real-world workloads.
  • Idiomatic Rust API with no_std compatibility where appropriate.
  • docs/design.md — Architectural overview and design goals.
  • docs/policies/README.md — Implemented policies and roadmap.
  • docs/policy-ds/README.md — Data structure implementations used by policies.
  • docs/policies.md — Policy survey and tradeoffs.
  • docs/style-guide.md — Documentation style guide.
  • docs/release-checklist.md — Release readiness checklist.
  • docs/releasing.md — How to cut a release (tag, CI, publish, docs).
  • docs/ci-cd-release-cycle.md — CI/CD overview for releases.
  • docs/integration.md — Integration notes (placeholder).
  • docs/metrics.md — Metrics notes (placeholder).

Add cachekit as a dependency in your Cargo.toml:

[dependencies]
cachekit = { git = "https://github.com/OxidizeLabs/cachekit" }
use cachekit::policy::lru_k::LRUKCache;

fn main() {
    // Create an LRU cache with a capacity of 100 entries
    let mut cache = LRUKCache::new(2);

    // Insert an item
    cache.insert("key1", "value1");

    // Retrieve an item
    if let Some(value) = cache.get(&"key1") {
        println!("Got from cache: {}", value);
    }
}
联系我们 contact @ memedata.com