Http Client Cache
internal class HttpClientCache(maxCacheSize: Int = 100, maxAge: Duration = 30.minutes, maxIdleTime: Duration = 10.minutes, cleanupInterval: Duration = 5.minutes)(source)
LRU cache for Ktor HttpClient instances keyed by authentication credentials.
Caches HTTP clients to avoid creating a new client per scrape request. Entries are evicted when they exceed maxAge, sit idle longer than maxIdleTime, or when the cache exceeds maxCacheSize (least-recently-used eviction). A background coroutine periodically cleans up expired entries. Credential-based keys are masked in logs to prevent leaking secrets.
Parameters
max Cache Size
maximum number of cached clients
max Age
maximum lifetime of a cache entry
max Idle Time
maximum idle time before an entry is considered expired
cleanup Interval
interval between background cleanup sweeps
See also
Types
Link copied to clipboard
class CacheEntry(val client: HttpClient, val createdAt: Long = System.currentTimeMillis(), var lastAccessedAt: Long = System.currentTimeMillis())
Link copied to clipboard
Functions
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun getOrCreateClient(key: HttpClientCache.ClientKey, clientFactory: () -> HttpClient): HttpClientCache.CacheEntry
Link copied to clipboard