📝 Add README
This commit is contained in:
parent
3367cce0df
commit
5cdc555fb6
1 changed files with 21 additions and 0 deletions
21
README.md
Normal file
21
README.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# ezcache
|
||||||
|
|
||||||
|
ezcache is a simple in-memory cache for golang that has data expiry.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```go
|
||||||
|
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.
|
||||||
|
```
|
||||||
Loading…
Add table
Add a link
Reference in a new issue