Example usage:
package main
import (
"fmt"
"github.com/andys/faststructcache"
)
type User struct {
ID uint32
Name string
Email string
}
func main() {
user := User{16123, "Austin Mackenzie", "austin.mackenzie@corporation.com"}
cache := faststructcache.New[uint32, User](32, true)
cache.Set(user.ID, user)
fmt.Printf("get = %+v\n", cache.Get(user.ID))
}Result: get = &{ID:16123 Name:Austin Mackenzie Email:austin.mackenzie@corporation.com}
import "github.com/andys/faststructcache"type FastStructCache
FastStructCache is an in-memory key-value store intended to be able to store larger structs (although any data type should work). It wraps fastcache from VictoriaMetrics with the binary codec from kelindar, and optional snappy-like compression (S2 from klauspost).
type FastStructCache[KT, VT any] struct {
Cache *fastcache.Cache
// contains filtered or unexported fields
}func New
func New[KT, VT any](mb int, compress bool) FastStructCache[KT, VT]New returns new cache with the given maxBytes capacity in bytes (min 32MB), with optional light compression.
func (FastStructCache[KT, VT]) Del
func (c FastStructCache[KT, VT]) Del(k KT)Del deletes value for the given k from the cache.
func (FastStructCache[KT, VT]) Get
func (c FastStructCache[KT, VT]) Get(k KT) *VTGet returns pointer to a value stored for given key k, or nil if it didn't exist in the cache
func (FastStructCache[KT, VT]) Has
func (c FastStructCache[KT, VT]) Has(k KT) boolHas returns true if entry for the given key k exists in the cache.
func (FastStructCache[KT, VT]) Reset
func (c FastStructCache[KT, VT]) Reset()Reset removes all the items from the cache.
func (FastStructCache[KT, VT]) Set
func (c FastStructCache[KT, VT]) Set(k KT, v VT)Set stores (k, v) in the cache.
Generated by gomarkdoc