kutil_http/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: 'static + Clone + fmt::Display + Eq + Hash + Send + CacheWeight + Sync {
14    /// Create a cache key for a request.
15    fn for_request(method: &Method, uri: &Uri, headers: &HeaderMap) -> Self;
16}
17
18//
19// CacheKeyForRequest
20//
21
22/// [CacheKey] for [Request].
23pub trait CacheKeyForRequest<CacheKeyT> {
24    /// Create a cache key.
25    fn cache_key(&self) -> CacheKeyT;
26}
27
28impl<RequestBodyT, CacheKeyT> CacheKeyForRequest<CacheKeyT> for Request<RequestBodyT>
29where
30    CacheKeyT: CacheKey,
31{
32    fn cache_key(&self) -> CacheKeyT {
33        CacheKeyT::for_request(self.method(), self.uri(), self.headers())
34    }
35}