pub trait CacheEntity {
type Id: ToString;
const ENTITY: &'static str;
const COLLECTION: Option<&'static str>;
// Provided methods
fn cache_key_for(id: &Self::Id) -> String { ... }
fn entity_tag_for(id: &Self::Id) -> String { ... }
fn collection_tag() -> Option<String> { ... }
}Expand description
Static cache metadata for a domain entity.
Implement this trait manually when you want domain-shaped cache calls without repeating entity and collection names at every query site. A future derive macro can generate the same implementation.
§Example
use hydracache_db::CacheEntity;
struct User;
impl CacheEntity for User {
type Id = i64;
const ENTITY: &'static str = "user";
const COLLECTION: Option<&'static str> = Some("users");
}
assert_eq!(User::cache_key_for(&42), "user:42");
assert_eq!(User::entity_tag_for(&42), "user:42");
assert_eq!(User::collection_tag(), Some("users".to_owned()));Required Associated Constants§
Sourceconst COLLECTION: Option<&'static str>
const COLLECTION: Option<&'static str>
Optional collection tag for broader invalidation groups.
Required Associated Types§
Provided Methods§
Sourcefn cache_key_for(id: &Self::Id) -> String
fn cache_key_for(id: &Self::Id) -> String
Build the logical cache key for this entity id.
Sourcefn entity_tag_for(id: &Self::Id) -> String
fn entity_tag_for(id: &Self::Id) -> String
Build the entity invalidation tag for this id.
Sourcefn collection_tag() -> Option<String>
fn collection_tag() -> Option<String>
Build the optional collection invalidation tag.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".