https://github.com/mccutchen/fillcache
A simple in-process cache with single-flight filling semantics
https://github.com/mccutchen/fillcache
cache go golang singleflight
Last synced: over 1 year ago
JSON representation
A simple in-process cache with single-flight filling semantics
- Host: GitHub
- URL: https://github.com/mccutchen/fillcache
- Owner: mccutchen
- License: mit
- Created: 2018-06-15T15:57:55.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-16T02:16:39.000Z (over 1 year ago)
- Last Synced: 2024-10-18T12:44:15.976Z (over 1 year ago)
- Topics: cache, go, golang, singleflight
- Language: Go
- Homepage: https://pkg.go.dev/github.com/mccutchen/fillcache
- Size: 29.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fillcache
[](https://pkg.go.dev/github.com/mccutchen/fillcache)
[](https://github.com/mccutchen/fillcache/actions/workflows/ci.yaml)
[](https://codecov.io/gh/mccutchen/fillcache)
[](https://goreportcard.com/report/github.com/mccutchen/fillcache)
An in-process cache with single-flight filling semantics.
In short: Given a function that computes the value to be cached for a key, it
will ensure that the function is called only once per key no matter how many
concurrent cache gets are issued for a key.
This might be useful if, say, you find yourself reaching for the
[`singleflight` package][singleflight] _and_ you want to cache the resulting
values in memory.
## Usage
See [example_test.go](/example_test.go) for example usage.
## Testing
```bash
make test
```
## Credits
If you like this package, all credit should go to [@jphines][jphines], who
suggested the initial design as we were working through an in-process DNS
caching mechanism.
If you don't like its design or its implementation, all blame lies with
[@mccutchen][mccutchen].
[singleflight]: https://godoc.org/golang.org/x/sync/singleflight
[jphines]: https://github.com/jphines
[mccutchen]: https://github.com/mccutchen