https://github.com/mgnsk/evcache
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.
https://github.com/mgnsk/evcache
agecache cache capacity deduplication expiry fetch go golang lfu lru map realloc sync ttl ttl-cache
Last synced: 7 months ago
JSON representation
Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.
- Host: GitHub
- URL: https://github.com/mgnsk/evcache
- Owner: mgnsk
- License: mit
- Created: 2021-01-18T22:05:37.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-17T14:49:14.000Z (9 months ago)
- Last Synced: 2025-01-17T15:44:17.705Z (9 months ago)
- Topics: agecache, cache, capacity, deduplication, expiry, fetch, go, golang, lfu, lru, map, realloc, sync, ttl, ttl-cache
- Language: Go
- Homepage:
- Size: 416 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# evcache
[](https://pkg.go.dev/github.com/mgnsk/evcache/v4)
[](https://goreportcard.com/report/github.com/mgnsk/evcache/v4)Package evcache implements a concurrent key-value cache with capacity overflow eviction, item expiry and deduplication.
### Example
```go
package mainimport (
"time""github.com/mgnsk/evcache/v4"
)func main() {
c := evcache.New[string, string](
evcache.WithCapacity(128),
evcache.WithPolicy(evcache.LRU),
evcache.WithTTL(time.Minute),
)// Fetches an existing value or calls the callback to get a new value.
result, err := c.Fetch("key", func() (string, error) {
// Possibly a very long network call. It only blocks write access to this key.
// Read access for this key returns as if the value does not exist.
return "value", nil
})if err != nil {
panic(err)
}// Use the result.
println(result)
}
```