pmylund/go-cache — pull request #16 by Kovensky (2014-12-11 08:42:06+00:00)
Title: Do not register types with encoding/gob

Registering the same type multiple times can lead to a panic. While the
panic is handled in Save, the handling prevents saving the cache.

While doing this seems like a good idea (since then the caller wouldn't
have to register the types themselves), the need to deal with duplicate
entries causes issues with Load. If calling Load to initialize a cache
right after startup, encoding/gob will have no information about the
types written in the cache, and thus won't be able to load the cache.

There are also issues w.r.t. how the type is registered in gob, and
if they are registered in a different form inside go-cache than they
were outside, a panic happens due to different paths being generated:
https://github.com/golang/go/blob/master/src/encoding/gob/type.go#L857

Make sure that it's the caller's respansibility to register types with
encoding/gob, to avoid issues with gob's Register and so that they can
both Save and Load without having to Save beforehand in the same instance.