18#ifndef DETERMINISTICESPASYNCWEBSERVER_EDGE_CACHE_H
19#define DETERMINISTICESPASYNCWEBSERVER_EDGE_CACHE_H
23#if DETWS_ENABLE_EDGE_CACHE
38bool edge_header_value(
const char *hdrs,
size_t len,
const char *name,
char *out,
size_t out_cap);
43int64_t edge_parse_http_date(
const char *s,
size_t len);
54long edge_freshness_lifetime(
const DetwsCacheControl *cc,
bool shared, int64_t date_epoch, int64_t expires_epoch);
60long edge_heuristic_lifetime(int64_t date_epoch, int64_t last_modified_epoch);
67long edge_initial_age(int32_t age_hdr, int64_t date_epoch, int64_t response_time_epoch);
70long edge_current_age(
long initial_age, uint32_t insert_ms, uint32_t now_ms);
73bool edge_is_fresh_at(
long lifetime,
long current_age);
84size_t edge_key_canon(
const char *method,
const char *host,
const char *path,
const char *query,
bool include_query,
85 char *out,
size_t out_cap);
88void edge_key_digest(
const char *canon,
size_t len, uint8_t digest[32]);
91typedef const char *(*EdgeHdrLookup)(
void *ctx,
const char *name);
100bool edge_vary_serialize(
const char *vary_header, EdgeHdrLookup lookup,
void *ctx,
char *out,
size_t out_cap);
104#define EDGE_LRU_NONE 0xFFFFu
115 char content_type[64];
117 char last_modified[40];
118 char content_encoding[32];
120 int64_t expires_epoch;
125 uint32_t last_used_ms;
126 uint16_t lru_prev, lru_next;
134 uint32_t hits, misses, revalidations_304, replaces_200;
135 uint32_t stores, evictions, purges, l2_spills, l2_promotes;
136 uint64_t bytes_stored;
146typedef void (*EdgeEvictFn)(
void *ctx,
const EdgeEntry *victim);
152 uint16_t lru_head, lru_tail;
153 EdgeCacheStats stats;
154 EdgeEvictFn on_evict;
159void edge_store_init(EdgeCacheStore *s);
168EdgeEntry *edge_store_alloc(EdgeCacheStore *s,
const char *canon,
const char *vary_key);
174EdgeEntry *edge_store_lookup(EdgeCacheStore *s,
const char *canon,
const char *vary_key, uint32_t now_ms);
183EdgeEntry *edge_store_find(EdgeCacheStore *s,
const char *canon, EdgeHdrLookup lookup,
void *ctx, uint32_t now_ms);
186void edge_entry_set_freshness(EdgeEntry *e,
const DetwsCacheControl *cc,
bool shared, int64_t date_epoch,
187 int64_t expires_epoch, int64_t last_modified_epoch, int32_t age_hdr,
188 int64_t response_time_epoch, uint32_t now_ms);
191bool edge_entry_has_validator(
const EdgeEntry *e);
194bool edge_entry_fresh(
const EdgeEntry *e, uint32_t now_ms);
200uint32_t edge_store_sweep(EdgeCacheStore *s, uint32_t now_ms);
203uint32_t edge_store_purge(EdgeCacheStore *s,
const char *canon);
206uint32_t edge_store_purge_prefix(EdgeCacheStore *s,
const char *prefix);
209void edge_store_free_entry(EdgeCacheStore *s, EdgeEntry *e);
218bool edge_is_storeable(
int status,
const char *method,
const DetwsCacheControl *cc,
const char *vary_header,
228size_t edge_build_conditional(
const EdgeEntry *e,
char *out,
size_t cap);
237void edge_apply_304(EdgeEntry *e,
const char *new_hdrs,
size_t hdr_len, int64_t response_time_epoch, uint32_t now_ms);
User-facing configuration for DeterministicESPAsyncWebServer.
#define DETWS_EDGE_BODY_MAX
#define DETWS_EDGE_CACHE_SLOTS
#define DETWS_EDGE_VARY_MAX
#define DETWS_EDGE_KEY_MAX
HTTP Cache-Control directive builder + parser + freshness helper (RFC 9111), DETWS_ENABLE_HTTP_CACHE.