drpccache

package
v0.0.34 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2024 License: MIT Imports: 2 Imported by: 1

README

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.

Documentation

Overview

Package drpccache implements per stream cache for drpc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithContext

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

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

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL