Note about channels being unserializable
This commit is contained in:
parent
106d5795c8
commit
d5cd41da53
4
README
4
README
|
@ -141,7 +141,9 @@ func (c *Cache) Flush()
|
||||||
Deletes all items from the cache.
|
Deletes all items from the cache.
|
||||||
|
|
||||||
func (c *cache) Save(w io.Writer) error
|
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
|
func (c *cache) SaveFile(fname string) error
|
||||||
Saves the cache's items to the given filename, creating the file if it
|
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) {
|
func BenchmarkCacheGet(b *testing.B) {
|
||||||
tc := New(0, 0)
|
tc := New(0, 0)
|
||||||
tc.Set("foo", "bar", 0)
|
tc.Set("foo", "bar", 0)
|
||||||
|
|
Loading…
Reference in New Issue