18#ifndef PROTOCORE_EDGE_CACHE_H
19#define PROTOCORE_EDGE_CACHE_H
23#if PC_ENABLE_EDGE_CACHE
39bool edge_header_value(
const char *hdrs,
size_t len,
const char *name,
char *out,
size_t out_cap);
44int64_t edge_parse_http_date(
const char *s,
size_t len);
55long edge_freshness_lifetime(
const pc_cache_control *cc,
bool shared, int64_t date_epoch, int64_t expires_epoch);
61long edge_heuristic_lifetime(int64_t date_epoch, int64_t last_modified_epoch);
68long edge_initial_age(int32_t age_hdr, int64_t date_epoch, int64_t response_time_epoch);
71long edge_current_age(
long initial_age, uint32_t insert_ms, uint32_t now_ms);
74bool edge_is_fresh_at(
long lifetime,
long current_age);
85size_t edge_key_canon(
const char *method,
const char *host,
const char *path,
const char *query,
bool include_query,
86 char *out,
size_t out_cap);
89void edge_key_digest(
const char *canon,
size_t len, uint8_t digest[32]);
92using EdgeHdrLookup =
const char *(*)(
void *ctx,
const char *name);
101bool edge_vary_serialize(
const char *vary_header, EdgeHdrLookup lookup,
void *ctx,
char *out,
size_t out_cap);
105#define PC_EDGE_LRU_NONE 0xFFFFu
110#if PC_EDGE_LASTMOD_MAX < PC_HTTP_DATE_MAX
111#error "PC_EDGE_LASTMOD_MAX must be >= PC_HTTP_DATE_MAX (RFC 7231 IMF-fixdate + NUL)"
127 int64_t expires_epoch;
132 uint32_t last_used_ms;
147 uint32_t revalidations_304;
148 uint32_t replaces_200;
153 uint32_t l2_promotes;
155 uint32_t mesh_misses;
156 uint64_t bytes_stored;
166using EdgeEvictFn = void (*)(
void *ctx,
const EdgeEntry *victim);
174 EdgeCacheStats stats;
175 EdgeEvictFn on_evict;
180void edge_store_init(EdgeCacheStore *s);
189EdgeEntry *edge_store_alloc(EdgeCacheStore *s,
const char *canon,
const char *vary_key);
195EdgeEntry *edge_store_lookup(EdgeCacheStore *s,
const char *canon,
const char *vary_key, uint32_t now_ms);
204EdgeEntry *edge_store_find(EdgeCacheStore *s,
const char *canon, EdgeHdrLookup lookup,
void *ctx, uint32_t now_ms);
207void edge_entry_set_freshness(EdgeEntry *e,
const pc_cache_control *cc,
bool shared, int64_t date_epoch,
208 int64_t expires_epoch, int64_t last_modified_epoch, int32_t age_hdr,
209 int64_t response_time_epoch, uint32_t now_ms);
212bool edge_entry_has_validator(
const EdgeEntry *e);
215bool edge_entry_fresh(
const EdgeEntry *e, uint32_t now_ms);
221uint32_t edge_store_sweep(EdgeCacheStore *s, uint32_t now_ms);
224uint32_t edge_store_purge(EdgeCacheStore *s,
const char *canon);
227uint32_t edge_store_purge_prefix(EdgeCacheStore *s,
const char *prefix);
230void edge_store_free_entry(EdgeCacheStore *s,
const EdgeEntry *e);
239bool edge_is_storeable(
int status,
const char *method,
const pc_cache_control *cc,
const char *vary_header,
249size_t edge_build_conditional(
const EdgeEntry *e,
char *out,
size_t cap);
258void edge_apply_304(EdgeEntry *e,
const char *new_hdrs,
size_t hdr_len, int64_t response_time_epoch, uint32_t now_ms);
#define PC_EDGE_CACHE_SLOTS
Render a Unix epoch as an RFC 7231 IMF-fixdate.
HTTP Cache-Control directive builder + parser + freshness helper (RFC 9111), PC_ENABLE_HTTP_CACHE.
User-facing configuration for ProtoCore.
#define PC_EDGE_ETAG_MAX
Stored validator (ETag, quotes included).
#define PC_EDGE_CENC_MAX
Stored Content-Encoding to replay (e.g. gzip).
#define PC_EDGE_CTYPE_MAX
Stored Content-Type to replay.
#define PC_EDGE_LASTMOD_MAX
Stored Last-Modified (RFC 1123 date).