Documentation ¶
Overview ¶
A utility library for building caching layers.
Index ¶
- type CacheOnStorage
- func (s *CacheOnStorage) Delete(key interface{}) error
- func (s *CacheOnStorage) DeleteMulti(keys ...interface{}) error
- func (s *CacheOnStorage) Flush() error
- func (s *CacheOnStorage) Get(key interface{}) (interface{}, error)
- func (s *CacheOnStorage) GetMulti(keys ...interface{}) ([]interface{}, error)
- func (s *CacheOnStorage) Set(item interface{}) error
- func (s *CacheOnStorage) SetMulti(items ...interface{}) error
- type GenericStorage
- func (s *GenericStorage) Delete(key interface{}) error
- func (s *GenericStorage) DeleteMulti(keys ...interface{}) error
- func (s *GenericStorage) Flush() error
- func (s *GenericStorage) Get(key interface{}) (interface{}, error)
- func (s *GenericStorage) GetMulti(keys ...interface{}) ([]interface{}, error)
- func (s *GenericStorage) Set(item interface{}) error
- func (s *GenericStorage) SetMulti(items ...interface{}) error
- type GenericStorageOptions
- type LocalMapStorage
- type RateLimitedStorage
- func (s *RateLimitedStorage) Delete(key interface{}) error
- func (s *RateLimitedStorage) DeleteMulti(keys ...interface{}) error
- func (s *RateLimitedStorage) Flush() error
- func (s *RateLimitedStorage) Get(key interface{}) (interface{}, error)
- func (s *RateLimitedStorage) GetMulti(keys ...interface{}) ([]interface{}, error)
- func (s *RateLimitedStorage) Set(item interface{}) error
- func (s *RateLimitedStorage) SetMulti(items ...interface{}) error
- type Storage
- func NewCacheOnStorage(cache Storage, storage Storage) Storage
- func NewGenericStorage(name string, options GenericStorageOptions) Storage
- func NewLocalMapStorage(name string, KeyStringFunc ToStringFunc, ItemToKeyStringFunc ToStringFunc) Storage
- func NewRateLimitedStorage(storage Storage, maxConcurrency int) Storage
- type ToStringFunc
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 ¶
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 ¶
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)