https://github.com/yudai/ttlslicemap
TTL Slice Map for Caching in Go
https://github.com/yudai/ttlslicemap
Last synced: 8 months ago
JSON representation
TTL Slice Map for Caching in Go
- Host: GitHub
- URL: https://github.com/yudai/ttlslicemap
- Owner: yudai
- License: other
- Created: 2015-12-09T02:47:06.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-09T03:03:56.000Z (almost 10 years ago)
- Last Synced: 2024-12-28T13:18:10.354Z (9 months ago)
- Language: Go
- Size: 2.93 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TTL Slice Map for Caching
## How To Use
```sh
go get "github.com/yudai/ttlslicemap"
``````go
package mainimport (
"fmt"
"time""github.com/yudai/ttlslicemap"
)func main() {
// 5 minutes TTL
tsm := ttlslicemap.New(time.Minute * 5)// Add items
tsm.Add("one", "foo")
tsm.Add("one", "bar")
items, exists := tsm.Get("one")
fmt.Println(items) // => ["foo", "bar"]
fmt.Println(exists) // => true// Add more items
tsm.Add("two", "red")
tsm.Add("three", "blue")
fmt.Println(tsm.Count()) // => 3// Then remove one
tsm.Remove("one")
fmt.Println(tsm.Count()) // => 2// Wait expire
time.Sleep(time.Minute * 6)
fmt.Println(tsm.Count()) // => 0
}
```## License
The MIT License