README (view raw)
1myks
2----
3
4A barebones in-memory keystore in 125~ lines of actual code.
5
6
7FEATURES
8
9• Set key-value pairs with a given expiration.
10• Set key-value pairs without a given expiration.
11• Get values of any type (uses Go generics).
12• Delete unwanted values.
13• Probably not memory-safe!
14
15
16INSTALLING
17
18`go get github.com/BiRabittoh/myks`
19
20
21USAGE
22
23`ks := myks.New[string](5 * time.Minute)` creates a new instance and
24starts a goroutine that cleans up expired entries every 5 minutes.
25You can also pass `0` to disable the cleanup goroutine altogether.
26
27`go ks.StartCleanup(10 * time.Minute)` starts the cleanup goroutine
28at a later stage or changes its interval, if it's already started.
29
30`ks.Set("key", "value", 2 * time.Minute)` sets a new key-value pair
31with an expiration of 2 minutes.
32You can also pass `0` to keep that value until the app is stopped.
33
34`ks.Get("key")` returns a pointer to the set value and an error
35value (either nil, `ks.ErrNotFound` or `ks.ErrExpired`).
36
37`ks.Delete("key")` deletes a given key-value pair.
38
39`ks.Keys()` returns an iterator for all keys that are not expired.
40
41
42LICENSE
43
44myks is licensed under MIT.