mirror of
https://github.com/coredns/coredns.git
synced 2026-01-11 19:31:19 -05:00
Refactor: Update the cache getter function (#7800)
Rename the cache getter function to reflect the true functionality of retrieving with TTL consideration. Refs: https://github.com/coredns/coredns/issues/6505 Signed-off-by: Raisa Kabir <raisa.kabir2010@gmail.com>
This commit is contained in:
7
plugin/cache/handler.go
vendored
7
plugin/cache/handler.go
vendored
@@ -34,7 +34,7 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
// in which upstream doesn't support DNSSEC, the two cache items will effectively be the same. Regardless, any
|
||||
// DNSSEC RRs in the response are written to cache with the response.
|
||||
|
||||
i := c.getIgnoreTTL(now, state, server)
|
||||
i := c.getIfNotStale(now, state, server)
|
||||
if i == nil {
|
||||
crr := &ResponseWriter{ResponseWriter: w, Cache: c, state: state, server: server, do: do, ad: ad, cd: cd,
|
||||
nexcept: c.nexcept, pexcept: c.pexcept, wildcardFunc: wildcardFunc(ctx)}
|
||||
@@ -121,8 +121,8 @@ func (c *Cache) shouldPrefetch(i *item, now time.Time) bool {
|
||||
// Name implements the Handler interface.
|
||||
func (c *Cache) Name() string { return "cache" }
|
||||
|
||||
// getIgnoreTTL unconditionally returns an item if it exists in the cache.
|
||||
func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string) *item {
|
||||
// getIfNotStale returns an item if it exists in the cache and has not expired.
|
||||
func (c *Cache) getIfNotStale(now time.Time, state request.Request, server string) *item {
|
||||
k := hash(state.Name(), state.QType(), state.Do(), state.Req.CheckingDisabled)
|
||||
cacheRequests.WithLabelValues(server, c.zonesMetricLabel, c.viewMetricLabel).Inc()
|
||||
|
||||
@@ -146,6 +146,7 @@ func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string
|
||||
return nil
|
||||
}
|
||||
|
||||
// exists unconditionally returns an item if it exists in the cache.
|
||||
func (c *Cache) exists(state request.Request) *item {
|
||||
k := hash(state.Name(), state.QType(), state.Do(), state.Req.CheckingDisabled)
|
||||
if i, ok := c.ncache.Get(k); ok {
|
||||
|
||||
Reference in New Issue
Block a user