pub struct CacheKey { /* private fields */ }Expand description
A cache key identifying a cached entry.
Cache keys are composed of:
- A prefix for namespacing (e.g., “api”, “users”)
- A version number for cache invalidation
- A list of parts (key-value pairs) extracted from requests
§Cheap Cloning
CacheKey wraps its data in Arc, making clone() an O(1) operation
that only increments a reference count. This is important because keys
are frequently passed around during cache operations.
§Example
use hitbox_core::{CacheKey, KeyPart};
let key = CacheKey::new(
"api",
1,
vec![
KeyPart::new("method", Some("GET")),
KeyPart::new("path", Some("/users/123")),
],
);
assert_eq!(key.prefix(), "api");
assert_eq!(key.version(), 1);
assert_eq!(format!("{}", key), "api:v1:method=GET&path=/users/123");Implementations§
Source§impl CacheKey
impl CacheKey
Sourcepub fn memory_size(&self) -> usize
pub fn memory_size(&self) -> usize
Returns the estimated memory usage of this cache key in bytes.
This includes:
- Arc heap allocation (control block + CacheKeyInner)
- Vec heap allocation (KeyPart elements)
- SmolStr heap allocations (strings >23 bytes)
Sourcepub fn new(
prefix: impl Into<SmolStr>,
version: u32,
parts: Vec<KeyPart>,
) -> CacheKey
pub fn new( prefix: impl Into<SmolStr>, version: u32, parts: Vec<KeyPart>, ) -> CacheKey
Creates a new cache key with the given components.
§Arguments
prefix- Namespace prefix for the keyversion- Version number for cache invalidationparts- List of key-value parts
Trait Implementations§
Source§impl From<CacheKey> for OffloadKey
impl From<CacheKey> for OffloadKey
Source§impl Serialize for CacheKey
impl Serialize for CacheKey
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Decode<'de> for CacheKey
impl Encode for CacheKey
impl Eq for CacheKey
Auto Trait Implementations§
impl Freeze for CacheKey
impl RefUnwindSafe for CacheKey
impl Send for CacheKey
impl Sync for CacheKey
impl Unpin for CacheKey
impl UnwindSafe for CacheKey
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Returns whether the given value has been niched. Read more
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
Writes data to
out indicating that a T is niched.