rclone/vendor/storj.io/drpc/drpccache
Caleb Case e7bd392a69 backend/tardigrade: Upgrade to uplink v1.0.6
This fixes an important bug with listing that affects users with more
than 500 objects in a listing operation.
2020-05-29 18:00:08 +01:00
..
cache.go backend/tardigrade: Upgrade to uplink v1.0.6 2020-05-29 18:00:08 +01:00
doc.go backend/tardigrade: Upgrade to uplink v1.0.6 2020-05-29 18:00:08 +01:00
README.md backend/tardigrade: Upgrade to uplink v1.0.6 2020-05-29 18:00:08 +01:00

package drpccache

import "storj.io/drpc/drpccache"

Package drpccache implements per stream cache for drpc.

Usage

func WithContext

func WithContext(parent context.Context, cache *Cache) context.Context

WithContext returns a context with the value cache associated with the context.

type Cache

type Cache struct {
}

Cache is a per stream cache.

func FromContext

func FromContext(ctx context.Context) *Cache

FromContext returns a cache from a context.

Example usage:

cache := drpccache.FromContext(stream.Context())
if cache != nil {
       value := cache.LoadOrCreate("initialized", func() (interface{}) {
               return 42
       })
}

func New

func New() *Cache

New returns a new cache.

func (*Cache) Clear

func (cache *Cache) Clear()

Clear clears the cache.

func (*Cache) Load

func (cache *Cache) Load(key interface{}) interface{}

Load returns the value with the given key.

func (*Cache) LoadOrCreate

func (cache *Cache) LoadOrCreate(key interface{}, fn func() interface{}) interface{}

LoadOrCreate returns the value with the given key.

func (*Cache) Store

func (cache *Cache) Store(key, value interface{})

Store sets the value at a key.