Golang caching
This is a caching library heavily inspired by unkey-cache
It does not support all the features of unkey-cache yet.
- Tiered caching
- Memory Store
- Redis Store
Todo:
- [] Cloudflare Store
- [] Libsql Store
- [] Metric Middleware
- [] Encryption Middleware
Extra Features:
- SwrMany
- GetMany
- SetMany
Note
This package is still in development and most likely not ready for production use yet. Please report any issues you find.
go get github.com/steamsets/go-cache@latest
Please see example folder
package somePackage
import (
"github.com/steamsets/go-cache"
memoryStore "github.com/steamsets/go-cache/store/memory"
redisStore "github.com/steamsets/go-cache/store/redis"
)
type Cache struct {
User cache.Namespace[User]
Post cache.Namespace[Post]
}
type User struct {
Name string
Email string
}
type Post struct {
Title string
Description string
}
type Service struct {
cache *Cache
}
var service *Service
func init() {
memory := memoryStore.New(memoryStore.Config{
UnstableEvictOnSet: &memoryStore.UnstableEvictOnSetConfig{
Frequency: 1,
MaxItems: 100,
},
})
redis := redisStore.New(redisStore.Config{
Host: "localhost",
Port: 6379,
Username: "",
Password: "",
Database: 0,
})
c := Cache{
User: cache.NewNamespace[User]("user", nil, cache.NamespaceConfig{
Stores: []cache.Store{
redis,
},
Fresh: 45 * time.Minute,
Stale: 45 * time.Minute,
}),
Post: cache.NewNamespace[Post]("post", nil, cache.NamespaceConfig{
Stores: []cache.Store{
memory,
redis,
},
Fresh: 10 * time.Minute,
Stale: 10 * time.Minute,
}),
}
service = &Service{
cache: &c,
}
}
MIT License