Simple in-memory cache for go with expiry
Find a file
2025-04-21 14:44:06 -05:00
.gitignore 🚧 Scaffold stuff 2025-04-21 11:07:53 -05:00
.golangci.yaml 🚧 Scaffold stuff 2025-04-21 11:07:53 -05:00
cache.go ♻️ Rename ErrInvalidDuration to ErrInvalidExpiry 2025-04-21 11:24:51 -05:00
CHANGELOG.md 📝 Update CHANGELOG 2025-04-21 14:43:33 -05:00
example_test.go Add testable examples 2025-04-21 14:32:12 -05:00
ezcache.go It works! 2025-04-21 12:01:32 -05:00
ezcache_test.go Add testable examples 2025-04-21 14:32:12 -05:00
go.mod Add tests for New 2025-04-21 11:25:56 -05:00
go.sum Add tests for New 2025-04-21 11:25:56 -05:00
LICENSE 📄 Add LICENSE 2025-04-21 12:30:17 -05:00
README.md 📝 Add README 2025-04-21 12:16:34 -05:00
Taskfile.yml 🚧 Scaffold stuff 2025-04-21 11:07:53 -05:00

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.