The cache
package provides a simple in-memory key-value store for Go applications. With it, you can set, get, and delete key-value pairs easily.
Assuming you have Go installed and set up:
go get -u github.com/exortme1ster/cache
To start, initialize a new cache:
c := cache.New()
You can store any value associated with a string key and set time after which it will expire:
c.Set("1", 20, time.Second*3)
Retrieve a value by its key:
value := c.Get("myKey")
if value != nil {
fmt.Println(value) // Outputs: myValue
}
Remove a key and its associated value:
c.Delete("myKey")
Feel free to fork the repository and submit pull requests for any improvements or features you think would be useful.