Modified from https://github.com/fanjindong/go-cache with Generics in Go 1.18+.
2025-06-13 09:42:32 +08:00
.gitattributes chore: Initial commit 2022-06-13 16:50:16 +08:00
.gitignore chore: Initial commit 2022-06-13 16:50:16 +08:00
cache.go perf: do not new goroutine when clearInterval<=0 2024-08-04 12:35:13 +08:00
cache_test.go feat: cache clear method 2022-07-23 16:35:48 +08:00
config.go fix: missed generic param of config and option 2022-06-13 18:09:12 +08:00
go.mod chore: update package reference 2025-06-13 09:42:32 +08:00
hash.go chore: Initial commit 2022-06-13 16:50:16 +08:00
item.go feat: add back ICache interface 2022-06-13 20:50:43 +08:00
LICENSE chore: Initial commit 2022-06-13 16:50:16 +08:00
option.go feat: add back ICache interface 2022-06-13 20:50:43 +08:00
README.md chore: update package reference 2025-06-13 09:42:32 +08:00
shard.go feat: cache clear method 2022-07-23 16:35:48 +08:00

go-cache

Modified from https://github.com/fanjindong/go-cache with Generics in Go 1.18+.

Install

go get -u codeberg.org/alist/go-cache

Basic Usage

import "codeberg.org/alist/go-cache"

func main() {
    c := cache.NewMemCache[int]()
    c.Set("a", 1)
    c.Set("b", 1, cache.WithEx[int](1*time.Second))
    time.sleep(1*time.Second)
    c.Get("a") // 1, true
    c.Get("b") // nil, false
}