Just a quick tip about gob.register

This commit is contained in:
codewinch 2021-11-20 14:02:12 -06:00 committed by GitHub
parent 46f4078530
commit 96bed88262
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -26,7 +26,18 @@ import (
"time" "time"
) )
func initapp() {
// be sure to register your custom types before calling .CacheFrom()
gob.Register(MyStruct)
gob.Register(MyStruct2)
}
func main() { func main() {
// only needed if you are loading to/from external storage
// with .Items() and .CacheFrom()
initapp()
// Create a cache with a default expiration time of 5 minutes, and which // Create a cache with a default expiration time of 5 minutes, and which
// purges expired items every 10 minutes // purges expired items every 10 minutes
c := cache.New(5*time.Minute, 10*time.Minute) c := cache.New(5*time.Minute, 10*time.Minute)