Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyErmilov committed Sep 22, 2021
1 parent f89bf31 commit 74f6d10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
12 changes: 12 additions & 0 deletions examples/examples/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ use hitbox_axum::CacheLayer;
#[tokio::main]
async fn main() {
let cache_layer = CacheLayer::new();
// let cache_layer = CacheLayer::build()
// .with_ttl(30)
// .with_stale(30)
// .with_version(1)
// .with_cache_key_prefix("тыдыщь")
// .by_path()
// .by_path_extended(parse)
// .by_header("X-Request")
// .by_header("X-Location")
// .by_query()
// .by_body()
// .finish();
let app = Router::new().route("/users/:user_id/", get(handler.layer(cache_layer)));

let addr: SocketAddr = ([127, 0, 0, 1], 3000).into();
Expand Down
6 changes: 5 additions & 1 deletion hitbox-axum/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ use crate::service::CacheService;
use tower_layer::Layer;
use crate::CacheableRequest;

#[derive(Debug, Clone, Default)]
#[derive(Debug, Default)]
pub struct CacheConfig;

#[derive(Debug, Default)]
pub struct CacheLayer {
cache_key_prefix: Option<String>,
ttl: Option<u32>,
stale_ttl: Option<u32>,
cache_version: Option<u32>,
cache_config: CacheConfig,
}

impl CacheLayer {
Expand Down
3 changes: 1 addition & 2 deletions hitbox-axum/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::http::{Request, Response};
use futures::future::BoxFuture;
use tower_service::Service;

use crate::CacheableRequest;
use crate::{CacheableRequest, CacheLayer};
use hitbox::cache::Cacheable;

#[derive(Clone)]
Expand Down Expand Up @@ -34,7 +34,6 @@ impl<S, ReqBody, ResBody> Service<Request<ReqBody>> for CacheService<S>
}

fn call(&mut self, request: Request<ReqBody>) -> Self::Future {
// self.service.call(wrapper.into_inner())
let clone = self.service.clone();
let mut service = std::mem::replace(&mut self.service, clone);

Expand Down

0 comments on commit 74f6d10

Please sign in to comment.