httpx/sig/plugins/response_cache.rbs
HoneyryderChuck 7173616154 response cache: fix vary header handling by supporting a defined set of headers
the cache key will be also determined by the supported vary headers values, when present; this means easier lookups, and one level hash fetch, where the same url-verb request may have multiple entries depending on those headers

checking response vary header will therefore be something done at cache response lookup; writes may override when they shouldn't though, as a full match on supported vary headers will be performed, and one can't know in advance the combo of vary headers, which is why insterested parties will have to be judicious with the new  option
2025-04-12 22:09:12 +01:00

89 lines
2.1 KiB
Plaintext

module HTTPX
module Plugins
module ResponseCache
CACHEABLE_VERBS: Array[verb]
CACHEABLE_STATUS_CODES: Array[Integer]
SUPPORTED_VARY_HEADERS: Array[String]
def self?.cacheable_response?: (::HTTPX::ErrorResponse | cacheResponse response) -> bool
def self?.cached_response?: (response response) -> bool
interface _ResponseCacheOptions
def response_cache_store: () -> Store
def supported_vary_headers: () -> Array[String]
end
class Store
@store: Hash[String, cacheResponse]
@store_mutex: Thread::Mutex
def lookup: (cacheRequest request) -> cacheResponse?
def cached?: (cacheRequest request) -> boolish
def cache: (cacheRequest request, cacheResponse response) -> void
def prepare: (cacheRequest request) -> void
private
def match_by_vary?: (cacheRequest request, cacheResponse response) -> bool
def _get: (cacheRequest request) -> cacheResponse?
def _set: (cacheRequest request, cacheResponse response) -> void
end
module InstanceMethods
@response_cache: Store
def clear_response_cache: () -> void
def cacheable_request?: (cacheRequest request) -> bool
end
module RequestMethods
attr_accessor cached_response: cacheResponse?
@response_cache_key: String
def response_cache_key: () -> String
def cacheable_verb?: () -> bool
end
module ResponseMethods
@cache: bool
def cached?: () -> bool
def mark_as_cached!: () -> void
def copy_from_cached!: () -> void
def fresh?: () -> bool
def cache_control: () -> Array[String]?
def vary: () -> Array[String]?
private
def age: () -> Integer
def date: () -> Time
end
type cacheOptions = Options & _ResponseCacheOptions
type cacheRequest = Request & RequestMethods
type cacheResponse = Response & ResponseMethods
end
type sessionResponseCache = Session & ResponseCache::InstanceMethods
end
end