Updating readme with expiration constants

This commit is contained in:
Jason Mooberry 2014-11-10 15:52:23 -05:00
parent e8abf5f90b
commit df8252be86
1 changed files with 4 additions and 4 deletions

8
README
View File

@ -23,12 +23,12 @@ import "github.com/pmylund/go-cache"
c := cache.New(5*time.Minute, 30*time.Second) c := cache.New(5*time.Minute, 30*time.Second)
// Set the value of the key "foo" to "bar", with the default expiration time // Set the value of the key "foo" to "bar", with the default expiration time
c.Set("foo", "bar", 0) c.Set("foo", "bar", cache.DefaultExpiration)
// Set the value of the key "baz" to 42, with no expiration time // Set the value of the key "baz" to 42, with no expiration time
// (the item won't be removed until it is re-set, or removed using // (the item won't be removed until it is re-set, or removed using
// c.Delete("baz") // c.Delete("baz")
c.Set("baz", 42, -1) c.Set("baz", 42, cache.NoExpiration)
// Get the string associated with the key "foo" from the cache // Get the string associated with the key "foo" from the cache
foo, found := c.Get("foo") foo, found := c.Get("foo")
@ -61,7 +61,7 @@ if x, found := c.Get("foo"); found {
// foo can then be passed around freely as a string // foo can then be passed around freely as a string
// Want performance? Store pointers! // Want performance? Store pointers!
c.Set("foo", &MyStruct, 0) c.Set("foo", &MyStruct, cache.DefaultExpiration)
if x, found := c.Get("foo"); found { if x, found := c.Get("foo"); found {
foo := x.(*MyStruct) foo := x.(*MyStruct)
... ...
@ -73,7 +73,7 @@ if x, found := c.Get("foo"); found {
// pointer you've stored in the cache, retrieving that pointer with Get will // pointer you've stored in the cache, retrieving that pointer with Get will
// point you to the same data: // point you to the same data:
foo := &MyStruct{Num: 1} foo := &MyStruct{Num: 1}
c.Set("foo", foo, 0) c.Set("foo", foo, cache.DefaultExpiration)
... ...
x, _ := c.Get("foo") x, _ := c.Get("foo")
foo := x.(*MyStruct) foo := x.(*MyStruct)