// WithCache enables use of a cache. This will store all entries inserted from
// user space in a local cache (map) and will indicate the status of each
// individual entry.
491290
func (m *Map) WithCache() *Map {
	m.cache = map[string]*cacheEntry{}
	m.enableSync = true
	return m
}
1057108
func (ms *FileMsgStore) initCache() {
	ms.cache = &msgsCache{
		seqMaps: make(map[uint64]*cachedMsg),
	}
}
863345
func RequestCache(c context.Context) *lru.Cache {
	rc, _ := c.Value(&requestCacheKey).(*lru.Cache)
	if rc == nil {
		panic("server/caching: no request cache installed in Context")
	}
	return rc
}
912454
func (c *DNSCache) updateWithEntry(entry *cacheEntry) bool {
	changed := false
	entries, exists := c.forward[entry.Name]
	if !exists {
		changed = true
		entries = make(map[string]*cacheEntry)
		c.forward[entry.Name] = entries
	}

	if c.updateWithEntryIPs(entries, entry) {
		changed = true
	}

	// When lookupTime is much earlier than time.Now(), we may not expire all
	// entries that should be expired, leaving more work for .Lookup.
	if c.removeExpired(entries, time.Now(), time.Time{}) {
		changed = true
	}

	if c.perHostLimit > 0 && len(entries) > c.perHostLimit {
		c.overLimit[entry.Name] = true
	}
	return changed
}
353524
func NewCache(cacher Cacher) *Cache {
	h := &mNode{
		buckets:         make([]unsafe.Pointer, mInitialSize),
		mask:            mInitialSize - 1,
		growThreshold:   int32(mInitialSize * mOverflowThreshold),
		shrinkThreshold: 0,
	}
	for i := range h.buckets {
		h.buckets[i] = unsafe.Pointer(&mBucket{})
	}
	r := &Cache{
		mHead:  unsafe.Pointer(h),
		cacher: cacher,
	}
	return r
}
560990
func (h *HTTPBin) Cache(w http.ResponseWriter, r *http.Request) {
	if r.Header.Get("If-Modified-Since") != "" || r.Header.Get("If-None-Match") != "" {
		w.WriteHeader(http.StatusNotModified)
		return
	}

	lastModified := time.Now().Format(time.RFC1123)
	w.Header().Add("Last-Modified", lastModified)
	w.Header().Add("ETag", sha1hash(lastModified))
	h.Get(w, r)
}
1224136
func NewCache(maxSize uint64) *Cache {
	return &Cache{
		maxSize:      maxSize,
		store:        newRing(),
		lastSnapshot: time.Now(),
		tracker:      newCacheTracker(newCacheMetrics(nil), nil),
	}
}
76791
func WithGlobalCache(c context.Context, provider BlobCacheProvider) context.Context {
	return context.WithValue(c, &globalCacheKey, provider)
}
839250
func (builder *FetchCounterCommandBuilder) WithKey(key string) *FetchCounterCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
1221025
func NewWithCache(server string, client *Client, cache cache.Cache) *Config {
	return &Config{
		Server: server,
		Client: client,
		cache:  cache,
	}
}
585738
func (l *lru) CheckCache(mts []core.Metric, _ string) ([]core.Metric, []core.Metric) {
	return l.checkCache(mts)
}
398351
func (o *cacheOnce) cache(f func() error) {
	if atomic.LoadUint32(&o.done) == 1 {
		return
	}
	// Slow-path.
	o.m.Lock()
	defer o.m.Unlock()
	if o.done == 0 {
		err := f()
		if err == nil {
			atomic.StoreUint32(&o.done, 1)
		}
	}
}
570615
func (builder *UpdateSetCommandBuilder) WithKey(key string) *UpdateSetCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
396183
func (builder *FetchMapCommandBuilder) WithKey(key string) *FetchMapCommandBuilder {
	builder.protobuf.Key = []byte(key)
	return builder
}
926657
func (builder *UpdateCounterCommandBuilder) WithKey(key string) *UpdateCounterCommandBuilder {
	builder.key = key
	return builder
}
173236
func NewCacheWithHaunter(fs FileSystem, haunter Haunter) (Cache, error) {
	c := &cache{
		files:   make(map[string]fileStream),
		haunter: haunter,
		fs:      fs,
	}
	err := c.load()
	if err != nil {
		return nil, err
	}
	if haunter != nil {
		c.scheduleHaunt()
	}

	return c, nil
}
142084
func (user *User) Cache(key string, res interface{}) (exists bool) {
	return user.ctx.getCacheVal("user", key, res)
}