Write the cache's items (using Gob) to an io.Writer. NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the documentation for NewFrom().)
(w io.Writer)
| 961 | // NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the |
| 962 | // documentation for NewFrom().) |
| 963 | func (c *cache) Save(w io.Writer) (err error) { |
| 964 | enc := gob.NewEncoder(w) |
| 965 | defer func() { |
| 966 | if x := recover(); x != nil { |
| 967 | err = fmt.Errorf("Error registering item types with Gob library") |
| 968 | } |
| 969 | }() |
| 970 | c.mu.RLock() |
| 971 | defer c.mu.RUnlock() |
| 972 | for _, v := range c.items { |
| 973 | gob.Register(v.Object) |
| 974 | } |
| 975 | err = enc.Encode(&c.items) |
| 976 | return |
| 977 | } |
| 978 | |
| 979 | // Save the cache's items to the given filename, creating the file if it |
| 980 | // doesn't exist, and overwriting it if it does. |
no outgoing calls