https://github.com/octu0/concache
key-value with expiration in-memory store
https://github.com/octu0/concache
cache golang key-value memory-storage thread-safe-cache thread-safety
Last synced: 4 months ago
JSON representation
key-value with expiration in-memory store
- Host: GitHub
- URL: https://github.com/octu0/concache
- Owner: octu0
- License: mit
- Created: 2019-12-22T14:22:05.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-09-30T09:35:22.000Z (over 3 years ago)
- Last Synced: 2024-12-30T03:43:16.906Z (6 months ago)
- Topics: cache, golang, key-value, memory-storage, thread-safe-cache, thread-safety
- Language: Go
- Homepage: https://pkg.go.dev/github.com/octu0/concache
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `concache`
[](https://github.com/octu0/concache/blob/master/LICENSE)
[](https://godoc.org/github.com/octu0/concache)
[](https://goreportcard.com/report/github.com/octu0/concache)
[](https://github.com/octu0/concache/releases)`concache` is in-memory key:value cache. `concache` provides thread-safe `map[string]interface{}` with expiration times.
`concache` a high-performance solution to this by sharding the map with minimal time spent waiting for locks.## Documentation
https://godoc.org/github.com/octu0/concache
## Installation
```
$ go get github.com/octu0/concache
```## Example
```go
import(
"time"
"github.com/octu0/concache"
)func main(){
cache := concache.New(
concache.WithDefaultExpiration(5 * time.Second),
concache.WithCleanupInterval(10 * time.Minute),
)cache.Set("hello", "123", 1 * time.Second)
cache.SetDefault("world", "456")
if value, ok := cache.Get("hello"); ok {
println("hello " + value.(string))
}
if value, ok := cache.Get("world"); ok {
println("world " + value.(string))
}time.Sleep(1 * time.Second)
if _, ok := cache.Get("hello"); ok != true {
println("hello expired")
}
if _, ok := cache.Get("world"); ok {
println("world not expired")
}
}
```## License
MIT, see LICENSE file for details.