MCPcopy Create free account
hub / github.com/patrickmn/go-cache / Save

Method Save

cache.go:963–977  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 3

SaveFileMethod · 0.95
testFillAndSerializeFunction · 0.80

Calls

no outgoing calls

Tested by 2

testFillAndSerializeFunction · 0.64