https://github.com/jackc/cachet
The cache for all your Ts
https://github.com/jackc/cachet
Last synced: 8 months ago
JSON representation
The cache for all your Ts
- Host: GitHub
- URL: https://github.com/jackc/cachet
- Owner: jackc
- License: mit
- Created: 2023-03-11T13:58:19.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-03-11T21:19:47.000Z (over 2 years ago)
- Last Synced: 2025-01-26T06:43:17.548Z (9 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/jackc/cachet)

# CacheT
CacheT is a tiny, generic cache. It was initially designed to assist with live reloading HTML templates in development
while caching them in production.
## Example Usage
```go
value := 0
isStale := false
cache := cachet.Cache[int]{
Load: func() (int, error) {
value++
return value, nil
},
IsStale: func() (bool, error) {
return isStale, nil
},
}
cache.MustGet() // => 1
cache.MustGet() // => 1
isStale = true
cache.MustGet() // => 2
cache.MustGet() // => 3
isStale = false
cache.MustGet() // => 3
```