Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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,
})
```