Skip to main content

Module layer

Module layer 

Source
Expand description

Tower layer and builder for cache configuration. Tower layer and builder for HTTP caching.

This module provides Cache, a Tower Layer that wraps services with caching behavior, and CacheBuilder for fluent configuration.

§Examples

use std::time::Duration;
use hitbox::Config;
use hitbox::policy::PolicyConfig;
use hitbox_tower::Cache;
use hitbox_moka::MokaBackend;
use hitbox_http::extractors::Method;
use hitbox_http::predicates::{NeutralRequestPredicate, NeutralResponsePredicate};

let config = Config::builder()
    .request_predicate(NeutralRequestPredicate::new())
    .response_predicate(NeutralResponsePredicate::new())
    .extractor(Method::new())
    .policy(PolicyConfig::builder().ttl(Duration::from_secs(60)).build())
    .build();

let cache_layer = Cache::builder()
    .backend(MokaBackend::builder().max_entries(1000).build())
    .config(config)
    .build();

Structs§

Cache
Tower Layer that adds HTTP caching to a service.
CacheBuilder
Fluent builder for constructing a Cache layer.
NotSet
Marker type for unset builder fields.