MCPcopy Index your code
hub / github.com/patrickmn/go-cache / Load

Method Load

cache.go:1002–1017  ·  view source on GitHub ↗

Add (Gob-serialized) cache items from an io.Reader, excluding any items with keys that already exist (and haven't expired) in the current cache. NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)

(r io.Reader)

Source from the content-addressed store, hash-verified

1000// NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the
1001// documentation for NewFrom().)
1002func (c *cache) Load(r io.Reader) error {
1003 dec := gob.NewDecoder(r)
1004 items := map[string]Item{}
1005 err := dec.Decode(&items)
1006 if err == nil {
1007 c.mu.Lock()
1008 defer c.mu.Unlock()
1009 for k, v := range items {
1010 ov, found := c.items[k]
1011 if !found || ov.Expired() {
1012 c.items[k] = v
1013 }
1014 }
1015 }
1016 return err
1017}
1018
1019// Load and add cache items from the given filename, excluding any items with
1020// keys that already exist in the current cache.

Callers 2

LoadFileMethod · 0.95
testFillAndSerializeFunction · 0.80

Calls 1

ExpiredMethod · 0.80

Tested by 1

testFillAndSerializeFunction · 0.64