caching

package
Version: v0.0.0-...-09f4250 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2022 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

A utility library for building caching layers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CacheOnStorage

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

A storage implementation where a cache is layered on top of a storage. This implementation DOES NOT ensure data consistent between cache and storage when setting items.

NOTE: Dropbox internally uses a different caching implementation which performs two-phase cache invalidation; this ensures the cached data is consistent with the stored data.

func (*CacheOnStorage) Delete

func (s *CacheOnStorage) Delete(key interface{}) error

See Storage for documentation.

func (*CacheOnStorage) DeleteMulti

func (s *CacheOnStorage) DeleteMulti(keys ...interface{}) error

See Storage for documentation.

func (*CacheOnStorage) Flush

func (s *CacheOnStorage) Flush() error

See Storage for documentation.

func (*CacheOnStorage) Get

func (s *CacheOnStorage) Get(key interface{}) (interface{}, error)

See Storage for documentation.

func (*CacheOnStorage) GetMulti

func (s *CacheOnStorage) GetMulti(
	keys ...interface{}) ([]interface{}, error)

See Storage for documentation.

func (*CacheOnStorage) Set

func (s *CacheOnStorage) Set(item interface{}) error

See Storage for documentation.

func (*CacheOnStorage) SetMulti

func (s *CacheOnStorage) SetMulti(items ...interface{}) error

See Storage for documentation.

type GenericStorage

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

A generic storage implementation. The functionalities are provided by the user through GenericStorageOptions.

func (*GenericStorage) Delete

func (s *GenericStorage) Delete(key interface{}) error

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) DeleteMulti

func (s *GenericStorage) DeleteMulti(keys ...interface{}) error

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Flush

func (s *GenericStorage) Flush() error

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Get

func (s *GenericStorage) Get(key interface{}) (interface{}, error)

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) GetMulti

func (s *GenericStorage) GetMulti(keys ...interface{}) ([]interface{}, error)

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Set

func (s *GenericStorage) Set(item interface{}) error

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) SetMulti

func (s *GenericStorage) SetMulti(items ...interface{}) error

See Storage/GenericStorageOptions for documentation.

type GenericStorageOptions

type GenericStorageOptions struct {
	// GenericStorage will call either GetFunc or GetMultiFunc in its
	// Get and GetMulti implementations.  When neither one is available,
	// GenericStorage will return error.
	GetFunc      func(key interface{}) (interface{}, error)
	GetMultiFunc func(keys ...interface{}) ([]interface{}, error)

	// GenericStorage will call either SetFunc or SetMultiFunc in its
	// Set and SetMulti implementations.  When neither one is available,
	// GenericStorage will return error.
	SetFunc      func(item interface{}) error
	SetMultiFunc func(items ...interface{}) error

	// GenericStorage will call either DelFunc or DelMultiFunc in its
	// Del and DelMulti implementations.  When neither one is available,
	// GenericStorage will return error.
	DelFunc      func(key interface{}) error
	DelMultiFunc func(keys ...interface{}) error

	// When ErrorOnFlush is true, GenericStorage will always return error
	// on Flush calls.
	ErrorOnFlush bool

	// GenericStorage will call FlushFunc in its Flush implementation.  When
	// FlushFunc is unavailable (and ErrorOnFlush is false), GenericStorage
	// will do nothing and return nil.
	FlushFunc func() error
}

Options used in GenericStorage construction.

type LocalMapStorage

type LocalMapStorage struct {
}

type RateLimitedStorage

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

A storage implementation which limits the maximum number of concurrent operations.

func (*RateLimitedStorage) Delete

func (s *RateLimitedStorage) Delete(key interface{}) error

See Storage for documentation.

func (*RateLimitedStorage) DeleteMulti

func (s *RateLimitedStorage) DeleteMulti(keys ...interface{}) error

See Storage for documentation.

func (*RateLimitedStorage) Flush

func (s *RateLimitedStorage) Flush() error

See Storage for documentation.

func (*RateLimitedStorage) Get

func (s *RateLimitedStorage) Get(key interface{}) (interface{}, error)

See Storage for documentation.

func (*RateLimitedStorage) GetMulti

func (s *RateLimitedStorage) GetMulti(
	keys ...interface{}) ([]interface{}, error)

See Storage for documentation.

func (*RateLimitedStorage) Set

func (s *RateLimitedStorage) Set(item interface{}) error

See Storage for documentation.

func (*RateLimitedStorage) SetMulti

func (s *RateLimitedStorage) SetMulti(items ...interface{}) error

See Storage for documentation.

type Storage

type Storage interface {
	// This retrieves a single value from the storage.
	Get(key interface{}) (interface{}, error)

	// This retrieves multiple values from the storage.  The items are returned
	// in the same order as the input keys.
	GetMulti(keys ...interface{}) ([]interface{}, error)

	// This stores a single item into the storage.
	Set(item interface{}) error

	// This stores multiple items into the storage.
	SetMulti(items ...interface{}) error

	// This removes a single item from the storage.
	Delete(key interface{}) error

	// This removes multiple items from the storage.
	DeleteMulti(keys ...interface{}) error

	// This wipes all items from the storage.
	Flush() error
}

A generic key value storage interface. The storage may be persistent (e.g., a database) or volatile (e.g., cache). All Storage implementations must be thread safe.

func NewCacheOnStorage

func NewCacheOnStorage(
	cache Storage,
	storage Storage) Storage

This returns a CacheOnStorage, which adds a cache layer on top of the storage.

func NewGenericStorage

func NewGenericStorage(name string, options GenericStorageOptions) Storage

This creates a GenericStorage. See GenericStorageOptions for additional information.

func NewLocalMapStorage

func NewLocalMapStorage(
	name string,
	KeyStringFunc ToStringFunc,
	ItemToKeyStringFunc ToStringFunc) Storage

This returns a local non-persistent storage which uses map[string]interface{} as its underlying storage.

func NewRateLimitedStorage

func NewRateLimitedStorage(storage Storage, maxConcurrency int) Storage

This returns a RateLimitedStorage. This is useful for cases where high concurrent load may degrade the underlying storage's performance. NOTE: when maxConcurrency is non-positive, the original storage is returned (i.e., the storage is not rate limited).

type ToStringFunc

type ToStringFunc (func(key interface{}) string)

Jump to

Keyboard shortcuts

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