func (c *Cache) Set(m *dns.Msg) {
	if m == nil {
		return // no-op
	}
	if !isCacheable(m) {
		return
	}
	ok, key := key(m)
	if !ok {
		return
	}
	i := toItem(m)

	c.Lock()
	// lazy initialization for cache
	if c.items == nil {
		size := defaultCacheSize
		if c.cacheSize > 0 {
			size = c.cacheSize
		}
		c.items = gcache.New(size).LRU().Build()
	}
	c.Unlock()

	// set ttl as expiration time for item
	ttl := time.Duration(findLowestTTL(m)) * time.Second
	err := c.items.SetWithExpire(key, i, ttl)
	if err != nil {
		log.Printf("Couldn't set cache item")
	}
}
// Set saves a new dns message (question/answer) into the cache
Set saves a new dns message (question/answer) into the cache
// Set saves a new dns message ( question / answer ) into the cache
func (c *Cache) Set(m *dns.Msg) {
	if m == nil {
		return 
	}
	if !isCacheable(m) {
		return
	}
	ok, key := key(m)
	if !ok {
		return
	}
	i := toItem(m)
	c.Lock()
	if c.items == nil {
		size := defaultCacheSize
		if c.cacheSize > 0 {
			size = c.cacheSize
		}
		c.items = gcache.New(size).LRU().Build()
	}
	c.Unlock()
	ttl := time.Duration(findLowestTTL(m)) * time.Second
	err := c.items.SetWithExpire(key, i, ttl)
	if err != nil {
		log.Printf("Couldn't set cache item")
	}
}
func ( c * Cache ) Set ( m * dns . Msg ) { if m == nil { return } if ! isCacheable ( m ) { return } ok , key := key ( m ) if ! ok { return } i := toItem ( m ) c . Lock ( ) if c . items == nil { size := defaultCacheSize if c . cacheSize > 0 { size = c . cacheSize } c . items = gcache . New ( size ) . LRU ( ) . Build ( ) } c . Unlock ( ) ttl := time . Duration ( findLowestTTL ( m ) ) * time . Second err := c . items . SetWithExpire ( key , i , ttl ) if err != nil { log . Printf ( " " ) } }
Set saves a new dns message (question/answer) into the cache
Set saves a new dns message ( question / answer ) into the cache
// no-op // lazy initialization for cache // set ttl as expiration time for item