Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/michaelwp/go-cache
simple go library to manage number of data in cache
https://github.com/michaelwp/go-cache
Last synced: 10 days ago
JSON representation
simple go library to manage number of data in cache
- Host: GitHub
- URL: https://github.com/michaelwp/go-cache
- Owner: michaelwp
- Created: 2024-11-09T04:54:30.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-09T11:53:28.000Z (3 months ago)
- Last Synced: 2024-12-03T09:55:05.559Z (2 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-cache
simple go library to manage number of data in cacheinstallation:
```
go get -d github.com/michaelwp/go-cache
```example on how to use it:
```go
package mainimport (
"fmt"
gocache "github.com/michaelwp/go-cache"
)func main() {
capacity := int32(3)
cache := gocache.NewCache(capacity)// add new data to cache
cache.Add("A", "testA")
cache.Add("B", "testB")
cache.Add("C", "testC")
cache.Add("D", "testD")
cache.Add("E", "testE")// get data from cache
valA, isAExist := cache.Get("A")
if !isAExist {
fmt.Println("A key doesn't exist")
} else {
fmt.Println("A:", valA)
}valD, isDExist := cache.Get("D")
if !isDExist {
fmt.Println("D key doesn't exist")
} else {
fmt.Println("D:", valD)
}cache.Add("F", "testF")
cache.Add("G", "testG")fmt.Println("cache:", cache.View())
}```