Simple in-memory cache for go with expiry
| .gitignore | ||
| .golangci.yaml | ||
| cache.go | ||
| CHANGELOG.md | ||
| example_test.go | ||
| ezcache.go | ||
| ezcache_test.go | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| README.md | ||
| Taskfile.yml | ||
ezcache
ezcache is a simple in-memory cache for golang that has data expiry.
Usage
import "codeberg.org/danjones000/ezcache"
// ...
// Create a user cache which will cache users for five minutes
userCache := ezcache.New(func(id uint64) (User, error) {
// logic to fetch user from database
return User{}, nil
}, 5 * time.Minute)
user, err := user.Get(userID)
// Next time you do user.Get with the same userID within five minutes, it will be fetched from cache.
// After five minutes, it will fetch from the database again.