1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! # cache-kit
//!
//! A type-safe, fully generic, production-ready caching framework for Rust.
//!
//! ## Features
//!
//! - **Fully Generic:** Cache any type `T` that implements `CacheEntity`
//! - **Backend Agnostic:** Support for in-memory, Redis, Memcached, and custom backends
//! - **Database Agnostic:** Works with SQLx, tokio-postgres, Diesel, or custom repositories
//! - **Framework Independent:** Zero dependencies on web frameworks (Axum, Actix, Rocket, etc.)
//! - **Production Ready:** Built-in logging, metrics support, and error handling
//! - **Type Safe:** Compile-time verified, no magic strings
//!
//! ## Quick Start
//!
//! ### For Web Applications (Recommended)
//!
//! Use [`CacheService`] for easy sharing across threads:
//!
//! ```ignore
//! use cache_kit::{
//! CacheService, CacheEntity, CacheFeed, DataRepository,
//! backend::InMemoryBackend,
//! strategy::CacheStrategy,
//! };
//! use serde::{Deserialize, Serialize};
//!
//! // 1. Define your entity
//! #[derive(Clone, Serialize, Deserialize)]
//! struct User {
//! id: String,
//! name: String,
//! }
//!
//! // 2. Implement CacheEntity
//! impl CacheEntity for User {
//! type Key = String;
//! fn cache_key(&self) -> Self::Key { self.id.clone() }
//! fn cache_prefix() -> &'static str { "user" }
//! }
//!
//! // 3. Create feeder
//! struct UserFeeder {
//! id: String,
//! user: Option<User>,
//! }
//!
//! impl CacheFeed<User> for UserFeeder {
//! fn entity_id(&mut self) -> String { self.id.clone() }
//! fn feed(&mut self, entity: Option<User>) { self.user = entity; }
//! }
//!
//! // 4. Create cache (wrap backend in Arc automatically)
//! let cache = CacheService::new(InMemoryBackend::new());
//!
//! // 5. Use it - CacheService is Clone for thread sharing
//! let cache_clone = cache.clone(); // Cheap - just Arc increment
//! let mut feeder = UserFeeder { id: "user_1".to_string(), user: None };
//! cache.execute(&mut feeder, &repository, CacheStrategy::Refresh).await?;
//! ```
//!
//! ### For Custom Patterns (Advanced)
//!
//! Use [`CacheExpander`] for explicit control:
//!
//! ```ignore
//! use cache_kit::{CacheExpander, backend::InMemoryBackend};
//! use std::sync::Arc;
//!
//! // Lower-level API - wrap in Arc yourself if needed
//! let expander = CacheExpander::new(InMemoryBackend::new());
//! let cache = Arc::new(expander); // Manual Arc wrapping
//! let cache_clone = cache.clone();
//! ```
extern crate log;
// Re-exports for convenience
pub use CacheBackend;
pub use CacheEntity;
pub use ;
pub use ;
pub use CacheFeed;
pub use DataRepository;
pub use CacheService;
pub use CacheStrategy;
/// Library version
pub const VERSION: &str = env!;