KEEL 1.0.0
Minimal C11 HTTP client/server library built on epoll/kqueue/io_uring/poll
Loading...
Searching...
No Matches
Data Structures | Macros | Functions
resolver_cache.h File Reference
#include <stdint.h>
#include <keel/allocator.h>
#include <keel/resolver.h>
Include dependency graph for resolver_cache.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  KlResolverCacheConfig
 

Macros

#define KL_RESCACHE_DEFAULT_TTL_MS   60000
 
#define KL_RESCACHE_DEFAULT_CAPACITY   64
 

Functions

KlResolverkl_resolver_cache_create (KlResolver *inner, const KlResolverCacheConfig *cfg, KlAllocator *alloc)
 Create a caching resolver that wraps an inner resolver.
 
void kl_resolver_cache_clear (KlResolver *resolver)
 Evict all cached entries.
 
int kl_resolver_cache_count (const KlResolver *resolver)
 Return the number of occupied cache entries.
 

Macro Definition Documentation

◆ KL_RESCACHE_DEFAULT_TTL_MS

#define KL_RESCACHE_DEFAULT_TTL_MS   60000

resolver_cache.h — Caching DNS resolver decorator

Wraps any KlResolver and caches successful results with configurable TTL. Returns a KlResolver * that plugs directly into KlClientConfig.resolver.

Cache miss → delegates to inner resolver, stores result on completion. Cache hit → calls done_fn synchronously, returns immediately. Errors are never cached — the next resolve retries via the inner resolver.

◆ KL_RESCACHE_DEFAULT_CAPACITY

#define KL_RESCACHE_DEFAULT_CAPACITY   64

Function Documentation

◆ kl_resolver_cache_create()

KlResolver * kl_resolver_cache_create ( KlResolver inner,
const KlResolverCacheConfig cfg,
KlAllocator alloc 
)

Create a caching resolver that wraps an inner resolver.

The returned KlResolver * is the cache; destroy it via the vtable's destroy function. The inner resolver is borrowed (not owned) — the caller must destroy it separately after destroying the cache.

Parameters
innerInner resolver to delegate cache misses to (borrowed).
cfgConfig (NULL = defaults: 64 entries, 60 s TTL).
allocAllocator (borrowed).
Returns
KlResolver * on success, NULL on allocation failure.

◆ kl_resolver_cache_clear()

void kl_resolver_cache_clear ( KlResolver resolver)

Evict all cached entries.

◆ kl_resolver_cache_count()

int kl_resolver_cache_count ( const KlResolver resolver)

Return the number of occupied cache entries.