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)
| 979 | // NOTE: This method is deprecated in favor of c.Items() and NewFrom() (see the |
| 980 | // documentation for NewFrom().) |
| 981 | func (c *cache) Save(w io.Writer) (err error) { |
| 982 | enc := gob.NewEncoder(w) |
| 983 | defer func() { |
| 984 | if x := recover(); x != nil { |
| 985 | err = fmt.Errorf("Error registering item types with Gob library") |
| 986 | } |
| 987 | }() |
| 988 | c.mu.RLock() |
| 989 | defer c.mu.RUnlock() |
| 990 | for _, v := range c.items { |
| 991 | gob.Register(v.Object) |
| 992 | } |
| 993 | err = enc.Encode(&c.items) |
| 994 | return |
| 995 | } |
| 996 | |
| 997 | // Save the cache's items to the given filename, creating the file if it |
| 998 | // doesn't exist, and overwriting it if it does. |