Skip to main content

tower_http_cache_plus/cache/key/
key.rs

1use super::super::weight::*;
2
3use {
4    http::{header::*, uri::*, *},
5    std::{fmt, hash::*},
6};
7
8//
9// CacheKey
10//
11
12/// Cache key.
13pub trait CacheKey
14where
15    Self: 'static + Clone + fmt::Display + Eq + Hash + Send + CacheWeight + Sync,
16{
17    /// Create a cache key for a request.
18    fn for_request(method: &Method, uri: &Uri, headers: &HeaderMap) -> Self;
19}
20
21//
22// CacheKeyForRequest
23//
24
25/// [CacheKey] for [Request].
26pub trait CacheKeyForRequest<CacheKeyT> {
27    /// Create a cache key.
28    fn cache_key(&self) -> CacheKeyT;
29}
30
31impl<RequestBodyT, CacheKeyT> CacheKeyForRequest<CacheKeyT> for Request<RequestBodyT>
32where
33    CacheKeyT: CacheKey,
34{
35    fn cache_key(&self) -> CacheKeyT {
36        CacheKeyT::for_request(self.method(), self.uri(), self.headers())
37    }
38}