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)
| 1000 | // NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the |
| 1001 | // documentation for NewFrom().) |
| 1002 | func (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. |