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
//! An a implementation and infrastructure for asynchronous and clear cache integration. //! //! # A quick tour of hitbox //! //! Our crates consist of next main part: //! * [Cacheable] trait. //! * [Backend] trait and its implementation ([RedisBackend]). //! * [CacheableResponse] trait. //! * Cache implementation. ([hitbox-actix]) //! //! ## Features //! - [x] Automatic cache key generation. //! - [x] Framework integrations: //! - [x] Actix ([hitbox-actix]) //! - [ ] Actix-Web //! - [x] Multiple cache backend implementations: //! - [x] [RedisBackend] //! - [ ] In-memory backend //! - [x] Stale cache mechanics. //! - [ ] Cache locks for [dogpile effect] preventions. //! - [ ] Distributed cache locks. //! - [ ] Detailed metrics out of the box. //! //! ## Feature flags //! * derive - Support for [Cacheable] trait derive macros. //! * metrics - Support for metrics. //! //! ## Restrictions //! Default cache key implementation based on serde_qs crate //! and have some [restrictions](https://docs.rs/serde_qs/latest/serde_qs/#supported-types). //! //! ## Example //! First of all, you should derive [Cacheable] trait for your struct or enum: //! //! ```rust //! use hitbox::prelude::*; //! use serde::{Deserialize, Serialize}; //! //! #[derive(Cacheable, Serialize)] // With features=["derive"] //! struct Ping { //! id: i32, //! } //! ``` //! Or implement that trait manually: //! //! ```rust //! # use hitbox::{Cacheable, CacheError}; //! # struct Ping { id: i32 } //! impl Cacheable for Ping { //! fn cache_key(&self) -> Result<String, CacheError> { //! Ok(format!("{}::{}", self.cache_key_prefix(), self.id)) //! } //! //! fn cache_key_prefix(&self) -> String { "Ping".to_owned() } //! } //! ``` //! //! [Cacheable]: crate::Cacheable //! [CacheableResponse]: crate::CacheableResponse //! [Backend]: hitbox_backend::Backend //! [RedisBackend]: https://docs.rs/hitbox_redis/ //! [hitbox-actix]: https://docs.rs/hitbox_actix/ //! [dogpile effect]: https://www.sobstel.org/blog/preventing-dogpile-effect/ #![warn(missing_docs)] pub mod cache; pub mod dev; pub mod error; #[cfg(feature = "metrics")] pub mod metrics; pub mod response; pub mod runtime; pub mod settings; pub mod states; pub mod transition_groups; pub mod value; pub use cache::Cacheable; pub use error::CacheError; pub use response::{CachePolicy, CacheableResponse}; pub use value::{CacheState, CachedValue}; #[cfg(feature = "derive")] #[doc(hidden)] pub use serde_qs as hitbox_serializer; /// The `hitbox` prelude. pub mod prelude { #[cfg(feature = "derive")] pub use crate::hitbox_serializer; pub use crate::{CacheError, Cacheable, CacheableResponse}; }