Skip to main content

Module extractor

Module extractor 

Source
Expand description

Cache key extraction from requests.

This module provides the Extractor trait for extracting data from requests to build cache keys.

§Overview

Extractors pull relevant data from requests (like HTTP method, path, query parameters) and produce KeyParts that form the cache key. Multiple extractors can be chained to build complex cache keys.

§Composability

Extractors are designed to be composed. Protocol-specific crates like hitbox-http provide extractors for common request components that can be combined to create precise cache keys.

§Example

use hitbox_core::{Extractor, KeyParts, KeyPart};

#[derive(Debug)]
struct MethodExtractor;

#[async_trait::async_trait]
impl Extractor for MethodExtractor {
    type Subject = HttpRequest;

    async fn get(&self, request: Self::Subject) -> KeyParts<Self::Subject> {
        let mut parts = KeyParts::new(request);
        parts.push(KeyPart::new("method", Some(request.method().as_str())));
        parts
    }
}

Traits§

Extractor
Trait for extracting cache key components from a subject.