#![doc(html_root_url = "https://docs.rs/oxcache/0.2.0")]
#[macro_export]
macro_rules! has_feature {
($feature:expr) => {
cfg!(feature = $feature)
};
}
#[macro_export]
macro_rules! require_feature {
($required:expr, $dependent:expr) => {
const _: fn() = || {
if !$required && cfg!(feature = $dependent) {
panic!(
"Feature '{}' requires feature '{}' to be enabled. \
Add '{}' to your Cargo.toml features or use the 'full' feature.",
$dependent,
stringify!($required),
stringify!($required)
)
}
};
};
}
#[macro_export]
macro_rules! check_feature_dependence {
($dependent:expr, $required:expr) => {
const _: fn() = || {
if cfg!(feature = $dependent) && !$required && !cfg!(feature = "full") {
panic!(
"ERROR: '{}' feature requires '{}' feature.\n\
\n\
Solution 1: Enable required feature:\n\
oxcache = {{ version = \"0.1\", features = [\"{}\", \"{}\"] }}\n\
\n\
Solution 2: Enable all features:\n\
oxcache = {{ version = \"0.1\", features = [\"full\"] }}",
$dependent,
stringify!($required)
.replace("cfg!(feature = \\\"", "")
.replace("\\\")\"", ""),
$dependent,
stringify!($required)
.replace("cfg!(feature = \\\"", "")
.replace("\\\")\"", "")
)
}
};
};
}
#[macro_export]
macro_rules! add_feature_if_enabled {
($features:ident, $name:expr) => {
if cfg!(feature = $name) {
$features.push($name);
}
};
}
#[macro_export]
macro_rules! empty_struct {
($name:ident, $($traits:ident),+ $(,)?) => {
#[cfg(not(feature = "batch-write"))]
#[derive($($traits),+)]
pub struct $name;
#[cfg(not(feature = "batch-write"))]
impl $name {
pub fn new() -> Self {
Self
}
}
};
}
#[macro_export]
macro_rules! empty_struct_generic {
($name:ident $(<$($generics:tt),+>)?, $($traits:ident),+ $(,)?) => {
#[cfg(not(feature = "wal-recovery"))]
#[derive($($traits),+)]
pub struct $name $(<$($generics),+>)?;
#[cfg(not(feature = "wal-recovery"))]
impl $(<$($generics),+>)? $name $(<$($generics),+>)? {
pub fn new() -> Self {
Self
}
}
};
}
#[macro_export]
macro_rules! empty_async_methods {
($name:ident, { $(pub async fn $fn_name:ident(&self $(, $param:ident: $param_type: ty)* $(,)? ) -> Result<()> { $($body:stmt)* })+ }) => {
#[cfg(not(feature = "batch-write"))]
#[derive(Debug, Clone, Default)]
pub struct $name;
#[cfg(not(feature = "batch-write"))]
impl $name {
$(
pub async fn $fn_name(&self $(, $param: $param_type)*) -> Result<()> {
$($body)*
Ok(())
}
)+
}
};
}
#[macro_export]
macro_rules! empty_trait {
($name:ident, $($bounds:tt)*) => {
#[cfg(not(feature = "wal-recovery"))]
#[async_trait::async_trait]
pub trait $name: $($bounds)* {}
};
}
#[macro_export]
macro_rules! empty_async_fn {
(pub async fn $fn_name:ident (&self $(, $param:ident: $param_type: ty)*) -> Result<()>) => {
#[cfg(not(feature = "batch-write"))]
pub async fn $fn_name(&self $(, $param: $param_type)*) -> Result<()> {
Ok(())
}
};
}
#[macro_export]
macro_rules! placeholder_module {
($module:ident, $feature:expr) => {
#[cfg(not(feature = $feature))]
pub(crate) mod $module;
};
}
pub mod client;
pub mod config;
pub mod error;
#[deprecated(
since = "0.2.0",
note = "Internal module, will be made private in v0.3.0"
)]
pub mod manager;
#[doc(hidden)]
pub mod internal;
pub mod builder;
pub mod cache;
pub mod traits;
#[cfg(any(
feature = "l1-moka",
feature = "l2-redis",
feature = "minimal",
feature = "core",
feature = "full"
))]
pub mod backend;
#[cfg(any(feature = "bloom-filter", feature = "full"))]
pub mod bloom_filter;
#[cfg(any(
feature = "metrics",
feature = "l1-moka",
feature = "l2-redis",
feature = "minimal",
feature = "core",
feature = "full",
feature = "batch-write",
feature = "cli"
))]
pub mod metrics;
#[cfg(any(feature = "rate-limiting", feature = "full"))]
pub mod rate_limiting;
#[cfg(any(feature = "wal-recovery", feature = "l2-redis", feature = "full"))]
pub mod recovery;
#[cfg(any(
feature = "batch-write",
feature = "l2-redis",
feature = "sync",
feature = "full"
))]
pub mod sync;
#[cfg(any(feature = "database", feature = "full"))]
pub mod database;
#[cfg(any(feature = "opentelemetry", feature = "full"))]
pub mod telemetry;
#[cfg(any(feature = "serialization", feature = "full"))]
pub mod serialization;
#[cfg(any(feature = "full", feature = "minimal", feature = "core"))]
pub mod utils;
#[cfg(any(feature = "smart-strategy", feature = "full"))]
pub mod smart_strategy;
#[cfg(any(feature = "http-cache", feature = "full"))]
pub mod http;
pub mod security;
#[cfg(feature = "macros")]
pub use oxcache_macros::cached;
#[cfg(feature = "macros")]
pub mod macros {
pub use oxcache_macros::*;
}
pub use client::{CacheExt, CacheOps};
pub use config::legacy_config::{
CacheStrategy as LegacyCacheStrategy, DynamicConfig as LegacyDynamicConfig,
};
#[allow(deprecated)]
pub use config::Config;
pub use config::{
CacheStrategy, CacheType, DynamicConfig, GlobalConfig, OxcacheConfig, OxcacheConfigBuilder,
RedisMode, SerializationType, ServiceConfig,
};
#[cfg(feature = "confers")]
pub use config::ConfigSource;
#[cfg(feature = "l1-moka")]
pub use config::LayerConfig;
pub use config::LegacyEvictionPolicy as EvictionPolicy;
pub use error::{CacheError, Result};
pub use builder::{BackendBuilder, CacheBuilder, TieredCacheBuilder};
pub use cache::Cache;
pub use traits::{CacheKey, Cacheable};
#[cfg(any(
feature = "l1-moka",
feature = "l2-redis",
feature = "core",
feature = "full"
))]
pub use backend::custom_tiered::{
AutoFixConfig, BackendType, ConfigFix, ConfigValidationResult, CustomTieredConfig,
CustomTieredConfigBuilder, FixedConfigResult, Layer, LayerBackendConfig, LayerRestriction,
};
#[cfg(any(feature = "l2-redis", feature = "core", feature = "full"))]
pub use sync::warmup::{WarmupManager, WarmupResult, WarmupStatus};
pub use config::oxcache_config;
#[cfg(test)]
pub use config::L1Config;
#[cfg(any(feature = "l2-redis", feature = "full"))]
pub use config::L2Config;
#[cfg(test)]
pub use config::TwoLevelConfig;
#[cfg(any(feature = "full", feature = "minimal", feature = "core"))]
pub use utils::key_generator::KeyGenerator;
#[cfg(any(feature = "smart-strategy", feature = "full"))]
pub use smart_strategy::{
CompressibilityChecker, CompressionDecider, HitRateCollector, HitRateStats, PrefetchDecider,
SmartStrategyConfig, SmartStrategyManager,
};
#[cfg(any(feature = "enhanced-stats", feature = "metrics", feature = "full"))]
pub use metrics::{export_json_format, export_prometheus_format, get_enhanced_stats, CacheStats};
#[cfg(any(feature = "http-cache", feature = "full"))]
pub use http::{
CacheMiddlewareConfig, CacheMiddlewareState, HttpCacheAdapter, HttpCacheKeyGenerator,
HttpCachePolicy, HttpCacheResponse, HttpRequest,
};
#[doc(hidden)]
pub use internal::{__internal_get_cache, __internal_register_cache};
pub use internal::{
get_all_feature_info, get_l1_feature_info, get_l2_feature_info, is_l1_enabled, is_l2_enabled,
};
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
const _: fn() = || {
check_feature_dependence!("bloom-filter", cfg!(feature = "l1-moka"));
check_feature_dependence!("rate-limiting", cfg!(feature = "l1-moka"));
check_feature_dependence!("wal-recovery", cfg!(feature = "l2-redis"));
check_feature_dependence!("batch-write", cfg!(feature = "l2-redis"));
check_feature_dependence!("cli", cfg!(feature = "confers"));
check_feature_dependence!("opentelemetry", cfg!(feature = "metrics"));
check_feature_dependence!("database", cfg!(feature = "l2-redis"));
};