0 | 0 |
# TTLCache - an in-memory cache with expiration
|
1 | 1 |
|
2 | |
[](https://pkg.go.dev/github.com/ReneKroon/ttlcache/v2)
|
3 | |
[](https://github.com/ReneKroon/ttlcache/releases)
|
|
2 |
**Although v2 of ttlcache is not yet deprecated, v3 should be used as it
|
|
3 |
contains quite a few additions and improvements.**
|
4 | 4 |
|
5 | 5 |
TTLCache is a simple key/value cache in golang with the following functions:
|
6 | 6 |
|
|
14 | 14 |
|
15 | 15 |
Note (issue #25): by default, due to historic reasons, the TTL will be reset on each cache hit and you need to explicitly configure the cache to use a TTL that will not get extended.
|
16 | 16 |
|
17 | |
[](https://travis-ci.com/ReneKroon/ttlcache)
|
18 | |
[](https://goreportcard.com/report/github.com/ReneKroon/ttlcache)
|
19 | |
[](https://coveralls.io/github/ReneKroon/ttlcache?branch=master)
|
20 | |
[](https://github.com/ReneKroon/ttlcache/issues)
|
21 | |
[](https://github.com/ReneKroon/ttlcache/LICENSE)
|
22 | |
|
23 | 17 |
## Usage
|
24 | 18 |
|
25 | |
`go get github.com/ReneKroon/ttlcache/v2`
|
|
19 |
`go get github.com/jellydator/ttlcache/v2`
|
26 | 20 |
|
27 | 21 |
You can copy it as a full standalone demo program. The first snippet is basic usage, where the second exploits more options in the cache.
|
28 | 22 |
|
|
34 | 28 |
"fmt"
|
35 | 29 |
"time"
|
36 | 30 |
|
37 | |
"github.com/ReneKroon/ttlcache/v2"
|
|
31 |
"github.com/jellydator/ttlcache/v2"
|
38 | 32 |
)
|
39 | 33 |
|
40 | 34 |
var notFound = ttlcache.ErrNotFound
|
|
64 | 58 |
"fmt"
|
65 | 59 |
"time"
|
66 | 60 |
|
67 | |
"github.com/ReneKroon/ttlcache/v2"
|
|
61 |
"github.com/jellydator/ttlcache/v2"
|
68 | 62 |
)
|
69 | 63 |
|
70 | 64 |
var (
|