Note about channels being unserializable

master
Patrick Mylund Nielsen 13 years ago
parent 106d5795c8
commit d5cd41da53

@ -141,7 +141,9 @@ func (c *Cache) Flush()
Deletes all items from the cache.
func (c *cache) Save(w io.Writer) error
Writes the cache's items (using Gob) to an io.Writer.
Writes the cache's items (using Gob) to an io.Writer. Returns an error if
the serialization fails, e.g. because there are unserializable objects like
channels in the cache.
func (c *cache) SaveFile(fname string) error
Saves the cache's items to the given filename, creating the file if it

@ -551,6 +551,18 @@ func testFillAndSerialize(t *testing.T, tc *Cache) {
}
}
func TestSerializeUnserializable(t *testing.T) {
tc := New(0, 0)
ch := make(chan bool, 1)
ch <- true
tc.Set("chan", ch, 0)
fp := &bytes.Buffer{}
err := tc.Save(fp) // this should fail gracefully
if err.Error() != "gob NewTypeObject can't handle type: chan bool" {
t.Error("Error from Save was not gob NewTypeObject can't handle type chan bool:", err)
}
}
func BenchmarkCacheGet(b *testing.B) {
tc := New(0, 0)
tc.Set("foo", "bar", 0)

Loading…
Cancel
Save