-
Notifications
You must be signed in to change notification settings - Fork 1
JDWX DNSQuery Cache Cache
Implements a caching interface for response packets using a PSR-6/PSR-16 cache interface as the backend.
- Class name: Cache
- Namespace: \JDWX\DNSQuery\Cache
- Parent class: JDWX\DNSQuery\Cache\BaseCache
- This class implements: JDWX\DNSQuery\Cache\ICache
protected cache
- Visibility: protected
mixed JDWX\DNSQuery\Cache\Cache::__construct(?\Psr\SimpleCache\CacheInterface i_cache)
Build a new cache, optionally using an existing PSR-6/PSR-16 cache interface.
- Visibility: public
- i_cache ?\Psr\SimpleCache\CacheInterface - Existing cache interface to use or null to create a simple array cache.
?\JDWX\DNSQuery\Packet\ResponsePacket JDWX\DNSQuery\Cache\ICache::get(string i_key)
Retrieves a cached response packet based on the provided key.
- Visibility: public
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_key string - Key to look up in the cache
bool JDWX\DNSQuery\Cache\ICache::has(string i_key)
See if the cache has a given key.
- Visibility: public
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_key string - Key to look up in the cache
void JDWX\DNSQuery\Cache\BaseCache::putWithTTL(string i_key, \JDWX\DNSQuery\Packet\ResponsePacket i_rsp, int i_ttl)
Store a response in the cache with a precalculated time-to-live (TTL).
- Visibility: protected
- This method is abstract.
- This method is defined by JDWX\DNSQuery\Cache\BaseCache
- i_key string - Key for the new response
- i_rsp JDWX\DNSQuery\Packet\ResponsePacket - Response to cache
- i_ttl int - TTL in seconds to cache this response
int JDWX\DNSQuery\Cache\BaseCache::calculateTTL(\JDWX\DNSQuery\Packet\ResponsePacket i_rsp)
Compute the TTL for a response packet.
Uses the lowest TTL of any RR in the response.
The downside to using one TTL for the whole object, is that we'll invalidate entries before they actually expire, causing a real lookup to happen.
The upside is that we don't need to require() each RR type in the cache, so we can look at their individual TTLs on each run. we only unserialize the actual RR object when it's get() from the cache.
- Visibility: public
- This method is static.
- This method is defined by JDWX\DNSQuery\Cache\BaseCache
- i_rsp JDWX\DNSQuery\Packet\ResponsePacket - Response packet to compute the TTL
string JDWX\DNSQuery\Cache\ICache::hashRequest(\JDWX\DNSQuery\Packet\RequestPacket i_rsp)
Create cache hash key for a request packet.
- Visibility: public
- This method is static.
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_rsp JDWX\DNSQuery\Packet\RequestPacket - Request packet to hash
bool JDWX\DNSQuery\Cache\ICache::isTypeCacheable(string i_type)
Determine if an RR type is cacheable by this implementation.
- Visibility: public
- This method is static.
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_type string - The RR type string (e.g. "A" or "OPT")
\JDWX\DNSQuery\Packet\ResponsePacket JDWX\DNSQuery\Cache\ICache::getEx(string i_key)
Same as get() but throws an exception if the key is not found.
- Visibility: public
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_key string - Key to look up in the local cache
void JDWX\DNSQuery\Cache\ICache::put(string i_key, \JDWX\DNSQuery\Packet\ResponsePacket i_rsp)
Add a new key/response pair to the cache
- Visibility: public
- This method is defined by JDWX\DNSQuery\Cache\ICache
- i_key string - Key for the new response
- i_rsp JDWX\DNSQuery\Packet\ResponsePacket - Response to store in cache