oxcache 0.4.0

A high-performance multi-level cache library for Rust with L1 (memory) and L2 (Redis) caching.
Documentation
[package]
name = "oxcache"
version = "0.4.0"
edition = "2024"
rust-version = "1.85"
description = "A high-performance multi-level cache library for Rust with L1 (memory) and L2 (Redis) caching."
authors = ["Kirky.X"]
license = "MIT"
repository = "https://github.com/Kirky-X/oxcache"
readme = "README.md"
keywords = ["cache", "redis", "memory", "async", "performance"]
categories = ["caching", "asynchronous", "database"]

[lib]
name = "oxcache"
path = "src/lib.rs"

# ============================================================================
# MAIN DEPENDENCIES
# ============================================================================
[dependencies]
# Internal macros
oxcache_macros = { path = "macros", version = "0.4", optional = true }

# Async Runtime - 精简特性
tokio = { version = "1.52", default-features = false, features = [
    "rt",
    "rt-multi-thread",
    "sync",
    "time",
    "macros",
    "bytes",
] }
async-trait = "0.1"
once_cell = "1.21"

# Utilities
uuid = { version = "1.23", features = ["v4"] }

# Error Handling
[dependencies.anyhow]
version = "1.0"
optional = true

# trait-kit integration (optional, feature-gated via `kit`).
[dependencies.trait-kit]
version = "0.3"
features = ["async"]
optional = true
default-features = false

# ICU4X internationalization (always enabled, mandatory dependency).
# icu 2.2 provides locale-aware number/date/plural/collation formatting
# and localized error message display.
[dependencies.icu]
version = "2.2"

[dependencies.writeable]
version = "0.6"

# ============================================================================
# L1 CACHE DEPENDENCIES (Memory Cache)
# ============================================================================
[dependencies.moka]
version = "0.12"
default-features = false
features = ["future"]
optional = true

# In-memory concurrent map for internal state
[dependencies.dashmap]
version = "6.2"
optional = true

# ============================================================================
# L2 Cache Dependencies (Redis) - 精简特性
[dependencies.redis]
version = "1.5"
default-features = false
features = ["aio", "tokio-comp", "connection-manager", "cluster-async", "sentinel"]
optional = true

# ============================================================================
# Aerospike (independent protocol, feature-gated)
[dependencies.aerospike]
version = "2.1"
optional = true

# ============================================================================
# Serialization & Compression - 精简特性
[dependencies.serde]
version = "1.0"
features = ["derive"]
optional = true

[dependencies.serde_json]
version = "1.0"
features = ["unbounded_depth"]
optional = true

[dependencies.flate2]
version = "1.1"
optional = true

# Depth-limited deserialization: single-pass parse with configurable depth limit
[dependencies.serde_stacker]
version = "0.1"
optional = true

# ============================================================================
# OBSERVABILITY & METRICS
# ============================================================================
# Metrics 实现完全内置(src/infra/metrics/*),不依赖外部 otel crate。
# 如需 OTLP 导出,由应用层(如 limiteron)统一处理,避免重复初始化 tracer provider。

# Bloom Filter (optional, for negative query filtering)
[dependencies.bloomfilter]
version = "3.0"
optional = true

[dependencies.regex]
version = "1.13"
optional = true

# Chrono - 精简特性
[dependencies.chrono]
version = "0.4"
default-features = false
features = ["serde", "clock"]
optional = true

# ============================================================================
# DEV DEPENDENCIES
# ============================================================================
[dev-dependencies]
tempfile = "3.27"
serial_test = "4.0"
rand = "0.10"
criterion = { version = "0.8", features = ["async_tokio"] }
ctor = "1.0"
trybuild = "1.0"
tracing-subscriber = { version = "0.3", default-features = false, features = ["env-filter", "fmt"] }

# ============================================================================
# TEST DEPENDENCIES
# ============================================================================
[dev-dependencies.testcontainers]
version = "0.27"

[dev-dependencies.testcontainers-modules]
version = "0.15"
features = ["redis"]

[features]

# Default: Minimal feature set (L1 memory cache only)
# Users opt-in to higher tiers via features = ["core"] / ["full"]
default = ["minimal"]

# --------------------------------------------------------------------
# TIERED FEATURES
# --------------------------------------------------------------------

# Minimal: L1 memory cache only
minimal = [
    "memory",
    "tokio/time",
    "metrics",
    "serialization",
    "dep:chrono",
]

# Core: L1 + L2 (Redis)
core = [
    "minimal",
    "redis",
]

# Full: All features enabled
full = [
    "core",
    "macros",
    "compression",
    "batch-write",
    "lua-script",
    "cli",
    "testing",
    "dragonfly",
    "aerospike",
]

# --------------------------------------------------------------------
# CORE COMPONENT FEATURES
# --------------------------------------------------------------------

# L1 Memory Cache (Moka + DashMap)
# serde: needed for V: Serialize + Deserialize trait bounds and derives on type enums
memory = ["dep:moka", "dep:dashmap", "dep:serde"]

# L2 Distributed Cache (Redis)
redis = ["dep:redis", "dep:regex"]

# Dragonfly (Redis-compatible, wraps redis feature)
dragonfly = ["redis"]

# Aerospike (independent protocol, optional)
aerospike = ["dep:aerospike"]

# Proc macros for #[cached]
# 显式依赖 `minimal`:宏生成代码引用 `::oxcache::__internal_get_cache`,
# 该函数仅在 backend feature(memory/redis/minimal/core/full)启用时导出。
# 不加 `minimal` 会导致独立启用 `macros` 时编译失败。
macros = ["dep:oxcache_macros", "minimal"]

# Serialization (JSON)
serialization = ["dep:serde", "dep:serde_json", "dep:serde_stacker"]

# Compression (flate2)
# `flate2` 特性供 `#[cfg(feature = "flate2")]` 代码分支使用;
# `compression` 作为用户可见的聚合开关。
flate2 = ["dep:flate2"]
compression = ["dep:flate2", "flate2"]

# Tracing support (deprecated: tracing removed, feature kept for backward compatibility)
tracing = []

# Metrics & Observability (内置实现,无需外部 otel crate)
# metrics 代码使用 serde/serde_json 进行 JSON 导出,需 serialization feature
metrics = [
    "serialization",
    "dep:chrono",
    "dep:dashmap",
]

# Batch Write (buffered L2 writes)
batch-write = []

# Lua Script Execution
lua-script = ["redis"]

# CLI tools
cli = ["dep:dashmap", "metrics"]

# Testing support (exposes internal functions)
testing = []

# Bloom Filter decorator (negative query filtering)
bloom-filter = ["dep:bloomfilter"]

# trait-kit 0.3 AsyncKit integration (OxcacheModule). Pulls in trait-kit
# with the `async` feature only — default features are disabled (Rule 6).
kit = ["dep:trait-kit"]


[workspace]
resolver = "2"
members = [".", "macros", "examples"]

[workspace.dependencies]
tokio = { version = "1.52", default-features = false }
async-trait = "0.1"
tracing = { version = "0.1", default-features = false }
tracing-subscriber = { version = "0.3", default-features = false }
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0" }
chrono = { version = "0.4", default-features = false }
criterion = { version = "0.8", features = ["async_tokio"] }

# COMPILER OPTIMIZATIONS
# ============================================================================

# Release profile: Maximum performance
[profile.release]
opt-level = 3
lto = "fat"
codegen-units = 1
panic = "abort"
strip = true
overflow-checks = false

# Optimize all dependencies equally
[profile.release.package."*"]
opt-level = 3

# Release with debug info: For profiling and debugging release builds
[profile.release-with-debug]
inherits = "release"
debug = true
strip = false

# Dev profile: Fast compilation for development iteration
[profile.dev]
opt-level = 0
debug = true
incremental = true

# Dev optimized: Faster dev builds with some optimizations
[profile.dev-optimized]
inherits = "dev"
opt-level = 2
debug = true

# Test profile
[profile.test]
opt-level = 0
debug = true

# Benchmark profile: Use release optimizations
[profile.bench]
inherits = "release"

# Optimize heavy dependencies even in dev builds
[profile.dev.package.moka]
opt-level = 2

[profile.dev.package.redis]
opt-level = 2

[profile.dev.package.serde]
opt-level = 2

[profile.dev.package.serde_json]
opt-level = 2

[profile.dev.package.tokio]
opt-level = 2

# ============================================================================
# BENCHMARKS
# ============================================================================
[[bench]]
name = "modern_api_benchmark"
harness = false

[[bench]]
name = "redis_benchmark"
harness = false
required-features = ["redis"]

[[bench]]
name = "serialization_benchmark"
harness = false
required-features = ["serialization"]

[[bench]]
name = "dashmap_benchmark"
harness = false
required-features = ["memory"]

[[bench]]
name = "dragonfly_benchmark"
harness = false
required-features = ["dragonfly"]

[lints.rust]
unexpected_cfgs = "allow"