From d5cd41da53d41e0a9ecb1e79072d75ef81c30d0b Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Sun, 29 Jan 2012 04:04:33 +0100 Subject: [PATCH] Note about channels being unserializable --- README | 4 +++- cache_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README b/README index cbcf8c3..1c80bf9 100644 --- a/README +++ b/README @@ -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 diff --git a/cache_test.go b/cache_test.go index c11c8a6..113618c 100644 --- a/cache_test.go +++ b/cache_test.go @@ -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)