hitbox-fn
Function memoization for the Hitbox caching framework.
This crate provides tools for caching async function results using the hitbox FSM. It wraps function arguments and return types into the hitbox pipeline, handling cache key generation, serialization, and upstream execution.
Overview
- [
Cache] - Pre-configured cache with backend, policy, and concurrency settings - [
#[cached]] - Attribute macro that transforms async functions into cacheable functions - [
KeyExtract] - Trait for types to describe their cache key contribution - [
Arg] / [Skipped] - Wrappers to include or exclude function parameters from cache keys - [
FnExtractor] - BridgesKeyExtractto hitbox'sExtractortrait - [
FnUpstream] - Adapts async functions to hitbox'sUpstreamtrait
Quick Start
use *;
use MokaBackend;
use Duration;
;
async
// Build a reusable cache
let cache = builder
.backend
.policy
.build;
// Call through cache
let user = fetch_user
.cache
.await?;
// With cache context (hit/miss/stale info)
let = fetch_user
.cache
.with_context
.await;
Feature Flags
derive- Enable derive macros (#[cached],#[derive(KeyExtract)], etc.) viahitbox-deriverkyv_format- Enable rkyv zero-copy serialization support