gebn / ttlcache

Distributed cache library with support for TTLs and coordinated loads.
Apache License 2.0
1 stars 1 forks source link

Provide minimal singleton instance example #8

Closed gebn closed 3 years ago

gebn commented 3 years ago

func main() {
        base := ttlcache.NewBase(&ttlcache.BaseOpts{
                Name:                       "name",
                PeerPicker:                 PeerPicker{},
                AuthoritativeCacheCapacity: 5_000_000,
                HotCacheCapacity:           5_000,
                ParallelRequests:           50,
        })
        cache := base.Configure(&ttlcache.ConfigureOpts{
                OriginLoader: ttlcache.OriginLoaderFunc(func(_ context.Context, key string) ([]byte, lifetime.Lifetime, error) {
                        log.Printf("origin load for %v", key)
                        return []byte(key+"-value"), lifetime.New(time.Minute), nil
                }),
        })
}

type PeerPicker struct{}

func (p PeerPicker) PickPeer(key string) *memberlist.Node {
        return nil
}