https://github.com/flowerwrong/simplecache
simple cache library in go
https://github.com/flowerwrong/simplecache
Last synced: 10 months ago
JSON representation
simple cache library in go
- Host: GitHub
- URL: https://github.com/flowerwrong/simplecache
- Owner: FlowerWrong
- Created: 2020-06-03T05:04:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-03T05:20:59.000Z (over 5 years ago)
- Last Synced: 2023-02-26T22:32:21.308Z (almost 3 years ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple cache
## Usage
```golang
c := simplecache.New(1)
if !c.SetMaxMemory("2MB") {
log.Panicln("Set max memory for cache failed")
}
for i := 0; i < 1000; i++ {
err := c.Set(fmt.Sprintf("key%d", i), fmt.Sprintf("val%d", i), time.Second)
if err != nil {
log.Panicln(err)
}
}
v, ok := c.Get(fmt.Sprintf("key%d", 1))
if !ok {
log.Panicln("Not found")
}
log.Println("Found", v.(string))
c.Del(fmt.Sprintf("key%d", 1))
log.Println("keys ", c.Keys())
log.Println("keys len", c.Size())
c.Flush()
time.Sleep(time.Second * 2) // for GC
```