godropbox: github.com/dropbox/godropbox/caching Index | Files

package caching

import "github.com/dropbox/godropbox/caching"

A utility library for building caching layers.

Index

Package Files

cache_on_storage.go generic_storage.go interface.go local_map_storage.go rate_limited_storage.go

type CacheOnStorage Uses

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 Uses

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

See Storage for documentation.

func (*CacheOnStorage) DeleteMulti Uses

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

See Storage for documentation.

func (*CacheOnStorage) Flush Uses

func (s *CacheOnStorage) Flush() error

See Storage for documentation.

func (*CacheOnStorage) Get Uses

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

See Storage for documentation.

func (*CacheOnStorage) GetMulti Uses

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

See Storage for documentation.

func (*CacheOnStorage) Set Uses

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

See Storage for documentation.

func (*CacheOnStorage) SetMulti Uses

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

See Storage for documentation.

type GenericStorage Uses

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

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

func (*GenericStorage) Delete Uses

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

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) DeleteMulti Uses

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

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Flush Uses

func (s *GenericStorage) Flush() error

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Get Uses

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

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) GetMulti Uses

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

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) Set Uses

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

See Storage/GenericStorageOptions for documentation.

func (*GenericStorage) SetMulti Uses

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

See Storage/GenericStorageOptions for documentation.

type GenericStorageOptions Uses

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 Uses

type LocalMapStorage struct {
}

type RateLimitedStorage Uses

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

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

func (*RateLimitedStorage) Delete Uses

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

See Storage for documentation.

func (*RateLimitedStorage) DeleteMulti Uses

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

See Storage for documentation.

func (*RateLimitedStorage) Flush Uses

func (s *RateLimitedStorage) Flush() error

See Storage for documentation.

func (*RateLimitedStorage) Get Uses

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

See Storage for documentation.

func (*RateLimitedStorage) GetMulti Uses

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

See Storage for documentation.

func (*RateLimitedStorage) Set Uses

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

See Storage for documentation.

func (*RateLimitedStorage) SetMulti Uses

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

See Storage for documentation.

type Storage Uses

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 Uses

func NewCacheOnStorage(
    cache Storage,
    storage Storage) Storage

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

func NewGenericStorage Uses

func NewGenericStorage(name string, options GenericStorageOptions) Storage

This creates a GenericStorage. See GenericStorageOptions for additional information.

func NewLocalMapStorage Uses

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 Uses

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 Uses

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

Package caching imports 2 packages (graph). Updated 2017-11-18. Refresh now. Tools for package owners.