oxcache 0.2.0

A high-performance multi-level cache library for Rust with L1 (memory) and L2 (Redis) caching.
[package]
name = "oxcache"
version = "0.2.0"
edition = "2021"
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.2.0", optional = true }

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

# Utilities
uuid = { version = "~1.23", features = ["v4"] }
secrecy = { version = "~0.10", features = ["serde"] }
rand = "0.10"

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

# Tracing for logging and instrumentation
[dependencies.tracing]
version = "~0.1"
optional = true

# Configuration
[dependencies.toml]
version = "~1.1"
optional = true

# ============================================================================
# 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.2"
default-features = false
features = ["aio", "tokio-comp", "connection-manager", "cluster-async", "sentinel"]
optional = true

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

[dependencies.serde_json]
version = "~1.0"
optional = true

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

[dependencies.base64]
version = "0.22"
optional = false

# ============================================================================
# OBSERVABILITY & METRICS
# ============================================================================

[dependencies.opentelemetry]
version = "0.32"
optional = true

[dependencies.opentelemetry_sdk]
version = "0.32"
optional = true

[dependencies.tracing-opentelemetry]
version = "0.33"
optional = true

[dependencies.opentelemetry-otlp]
version = "0.32"
optional = true

[dependencies.tracing-subscriber]
version = "~0.3"
default-features = false
features = ["env-filter", "fmt"]
optional = true

# ============================================================================
# UTILITIES
# ============================================================================
[dependencies.tokio-util]
version = "~0.7"
optional = true

[dependencies.futures]
version = "~0.3"
optional = true

[dependencies.arc-swap]
version = "~1.9"

[dependencies.regex]
version = "~1.12"
optional = true

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

# ============================================================================
# CONFIGURATION
# ============================================================================

# CLI - 精简特性
[dependencies.clap]
version = "4.6"
features = ["derive", "env"]
optional = true

# ============================================================================
# DEV DEPENDENCIES
# ============================================================================
[dev-dependencies]
tempfile = "3.27"
serial_test = "3.5"
rand = "0.10"
criterion = { version = "~0.8", features = ["async_tokio"] }
ctor = "1.0"
mockall = "0.14.0"

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

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

[features]

# Default: Full feature set for maximum compatibility
default = ["full"]

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

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

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

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

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

# L1 Memory Cache (Moka + DashMap)
memory = ["dep:moka", "dep:dashmap"]

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

# Proc macros for #[cached]
macros = ["dep:oxcache_macros"]

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

# Compression (flate2)
compression = ["dep:flate2"]

# Tracing support
tracing = ["dep:tracing"]

# Metrics & Observability (OpenTelemetry)
metrics = [
    "dep:opentelemetry",
    "dep:opentelemetry_sdk",
    "dep:tracing-subscriber",
    "dep:tracing-opentelemetry",
    "dep:opentelemetry-otlp",
    "dep:chrono",
    "dep:tracing",
    "dep:dashmap",
]

# Batch Write (buffered L2 writes)
batch-write = ["dep:tokio-util"]

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

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

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

# 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

[lints.rust]
unexpected_cfgs = "allow"