|
|
|
@ -4,13 +4,14 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/num30/go-cache"
|
|
|
|
|
"git.sg.caj.me/caj/go-cache"
|
|
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
// Create a cache with a default expiration time of 5 minutes, and which
|
|
|
|
|
// purges expired items every 10 minutes
|
|
|
|
|
c := cache.New[string](5*time.Minute, 10*time.Minute)
|
|
|
|
|
c := cache.New[string, string](5*time.Minute, 10*time.Minute)
|
|
|
|
|
|
|
|
|
|
// Set the value of the key "foo" to "bar", with the default expiration time
|
|
|
|
|
c.Set("foo", "bar", cache.DefaultExpiration)
|
|
|
|
@ -27,7 +28,7 @@ func main() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Want performance? Store pointers!
|
|
|
|
|
structCache := cache.New[*time.Time](5*time.Minute, 10*time.Minute)
|
|
|
|
|
structCache := cache.New[string, *time.Time](5*time.Minute, 10*time.Minute)
|
|
|
|
|
structCache.Set("foo", &time.Time{}, cache.DefaultExpiration)
|
|
|
|
|
if x, found := structCache.Get("foo"); found {
|
|
|
|
|
fmt.Printf("Cached time %+v\n", x)
|
|
|
|
|