Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codecat/go-rollingcache
Simple rolling cache module for Go.
https://github.com/codecat/go-rollingcache
Last synced: 6 days ago
JSON representation
Simple rolling cache module for Go.
- Host: GitHub
- URL: https://github.com/codecat/go-rollingcache
- Owner: codecat
- License: mit
- Created: 2022-03-25T14:20:51.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-22T13:23:32.000Z (about 1 month ago)
- Last Synced: 2024-11-22T14:26:43.122Z (about 1 month ago)
- Language: Go
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License.txt
Awesome Lists containing this project
README
# Rolling cache
This is a simple "rolling cache" module for Go. It works as a continuous request loop, where the data is only updated in a specific interval.## Example usage
On-demand request API:
```go
// Start a cache loop with:
// - An interval of 30 seconds
// - An inactivity lifetime of 5 minutes (interval multiplied by 10)
// And return the byte data into `res`.
res, err := rollingcache.Get("https://httpbin.org/get", 30 * time.Second)
```Continuous request API:
```go
// Start a cache loop with some options. The returned object is a rollingcache.Cache pointer.
// You can use this pointer to get the cache data.
cache := rollingcache.Start("https://httpbin.org/get", rollingcache.Options{
Interval: 10 * time.Second,
})
```