Skip to content
/ gogo Public

gogo is an in-memory key-value cache library for Go.

Notifications You must be signed in to change notification settings

lzyim/gogo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

gogo

gogo is an in-memory key-value cache library for Go.

Any object can be cached, for a given duration or forever, and the cache can be safely used by multiple goroutines.

Installation

go get github.com/soloslee/gogo

Usage

import (
    "fmt"
    "github.com/soloslee/gogo/cache"
)

func main() {
    c := cache.New()

    // Set key "key" to hold the string value "hello", with 10 secondes to live.
    // If key already holds a value, it is overwritten, regardless of its type.
    c.Set("key", "hello", 10)

    // Set the value of the key "mykey" to 42, with no expiration time.
    // (the item won't be removed until it is re-set, or removed using
    // c.Del("mykey")
    c.Set("mykey", 42, cache.NoExpiration)

    // Get the value of key "mykey"
    value, found := c.Get("mykey")
    if found {
        fmt.Println(value)
    }

    // Increments the number stored at key "mykey" by ten.
    c.Incr("mykey", 10)

    // Decrements the number stored at key "mykey" by one.
    c.Decr("mykey", 1)

    // Get the expiration time of key "mykey".
    // The method returns -1 if the key exists but has no associated expire.
    expiration, found = c.TTL("mykey")

    // Returns the number of items in the cache.
    number := c.Count()

    // Delete all items from the cache.
    c.Flush()
}

License

goim is licensed under MIT license.

About

gogo is an in-memory key-value cache library for Go.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages