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)
| 1018 | // NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the |
| 1019 | // documentation for NewFrom().) |
| 1020 | func (c *cache) Load(r io.Reader) error { |
| 1021 | dec := gob.NewDecoder(r) |
| 1022 | items := map[string]Item{} |
| 1023 | err := dec.Decode(&items) |
| 1024 | if err == nil { |
| 1025 | c.mu.Lock() |
| 1026 | defer c.mu.Unlock() |
| 1027 | for k, v := range items { |
| 1028 | ov, found := c.items[k] |
| 1029 | if !found || ov.Expired() { |
| 1030 | c.items[k] = v |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | return err |
| 1035 | } |
| 1036 | |
| 1037 | // Load and add cache items from the given filename, excluding any items with |
| 1038 | // keys that already exist in the current cache. |