1# package drpccache 2 3`import "storj.io/drpc/drpccache"` 4 5Package drpccache implements per stream cache for drpc. 6 7## Usage 8 9#### func WithContext 10 11```go 12func WithContext(parent context.Context, cache *Cache) context.Context 13``` 14WithContext returns a context with the value cache associated with the context. 15 16#### type Cache 17 18```go 19type Cache struct { 20} 21``` 22 23Cache is a per stream cache. 24 25#### func FromContext 26 27```go 28func FromContext(ctx context.Context) *Cache 29``` 30FromContext returns a cache from a context. 31 32Example usage: 33 34 cache := drpccache.FromContext(stream.Context()) 35 if cache != nil { 36 value := cache.LoadOrCreate("initialized", func() (interface{}) { 37 return 42 38 }) 39 } 40 41#### func New 42 43```go 44func New() *Cache 45``` 46New returns a new cache. 47 48#### func (*Cache) Clear 49 50```go 51func (cache *Cache) Clear() 52``` 53Clear clears the cache. 54 55#### func (*Cache) Load 56 57```go 58func (cache *Cache) Load(key interface{}) interface{} 59``` 60Load returns the value with the given key. 61 62#### func (*Cache) LoadOrCreate 63 64```go 65func (cache *Cache) LoadOrCreate(key interface{}, fn func() interface{}) interface{} 66``` 67LoadOrCreate returns the value with the given key. 68 69#### func (*Cache) Store 70 71```go 72func (cache *Cache) Store(key, value interface{}) 73``` 74Store sets the value at a key. 75