Documentation ¶
Index ¶
- type Cache
- type CacheEncoder
- type CacheMetrics
- type GobCacheEncoder
- type LocalCache
- func (lc LocalCache) Delete(ctx context.Context, key string) error
- func (lc LocalCache) Get(ctx context.Context, key string, target interface{}) error
- func (lc LocalCache) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (lc LocalCache) Purge(ctx context.Context) error
- func (lc LocalCache) Set(ctx context.Context, key string, value interface{}) error
- func (lc LocalCache) SetBytes(ctx context.Context, key string, value []byte) error
- type LocalCacheConfig
- type MockCache
- func (mc *MockCache) Delete(ctx context.Context, key string) error
- func (mc *MockCache) Get(ctx context.Context, key string, target interface{}) error
- func (mc *MockCache) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (mc *MockCache) Purge(ctx context.Context) error
- func (mc *MockCache) Set(ctx context.Context, key string, value interface{}) error
- func (mc *MockCache) SetBytes(ctx context.Context, key string, value []byte) error
- type MockCacheEncoder
- type MockCacheMetrics
- func (mcc *MockCacheMetrics) DeleteHit()
- func (mcc *MockCacheMetrics) DeleteMiss()
- func (mcc *MockCacheMetrics) Hit()
- func (mcc *MockCacheMetrics) Miss()
- func (mcc *MockCacheMetrics) PurgeHit()
- func (mcc *MockCacheMetrics) PurgeMiss()
- func (mcc *MockCacheMetrics) Set()
- func (mcc *MockCacheMetrics) SetCollision()
- type MockTieredCacheCreator
- type MockedCacheEncoder
- type PrometheusCacheMetrics
- func (pcm *PrometheusCacheMetrics) DeleteHit()
- func (pcm *PrometheusCacheMetrics) DeleteMiss()
- func (pcm *PrometheusCacheMetrics) Hit()
- func (pcm *PrometheusCacheMetrics) Miss()
- func (pcm *PrometheusCacheMetrics) PurgeHit()
- func (pcm *PrometheusCacheMetrics) PurgeMiss()
- func (pcm *PrometheusCacheMetrics) Set()
- func (pcm *PrometheusCacheMetrics) SetCollision()
- type RemoteCache
- func (rc RemoteCache) Close()
- func (rc RemoteCache) Delete(ctx context.Context, key string) error
- func (rc RemoteCache) Get(ctx context.Context, key string, target interface{}) error
- func (rc RemoteCache) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (rc RemoteCache) Purge(ctx context.Context) error
- func (rc RemoteCache) Set(ctx context.Context, key string, value interface{}) error
- func (rc RemoteCache) SetBytes(ctx context.Context, key string, value []byte) error
- type RemoteCacheConfig
- type TieredCache
- func (tc TieredCache) Close()
- func (tc TieredCache) Delete(ctx context.Context, key string) error
- func (tc TieredCache) Get(ctx context.Context, key string, target interface{}) error
- func (tc TieredCache) GetBytes(ctx context.Context, key string) ([]byte, error)
- func (tc TieredCache) Purge(ctx context.Context) error
- func (tc TieredCache) Set(ctx context.Context, key string, value interface{}) error
- func (tc TieredCache) SetBytes(ctx context.Context, key string, value []byte) error
- type TieredCacheConfig
- type TieredCacheCreator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { GetBytes(ctx context.Context, key string) ([]byte, error) Get(ctx context.Context, key string, target interface{}) error SetBytes(ctx context.Context, key string, value []byte) error Set(ctx context.Context, key string, value interface{}) error Delete(ctx context.Context, key string) error Purge(ctx context.Context) error }
Cache defines the interface for interacting with caching utilities. All derived caches must implement this interface
type CacheEncoder ¶
type CacheEncoder interface { // value must be a pointer Encode(value interface{}) ([]byte, error) // target must be a pointer Decode(cachedValue []byte, target interface{}) error }
CacheEncoder defines an interface for encoding and decoding values stored in cache
type CacheMetrics ¶
type CacheMetrics interface { Hit() Miss() Set() SetCollision() DeleteHit() DeleteMiss() PurgeHit() PurgeMiss() }
CacheMetrics defines an interface for recording cache metrics
type GobCacheEncoder ¶
type GobCacheEncoder struct{}
GobCacheEncoder uses encoding/gob to encode values for caching
func (*GobCacheEncoder) Decode ¶
func (gb *GobCacheEncoder) Decode(cachedValue []byte, target interface{}) error
Decode decodes the cached value using the gob encoding and sets the result in target. target must be a pointer
func (*GobCacheEncoder) Encode ¶
func (gb *GobCacheEncoder) Encode(value interface{}) ([]byte, error)
Encode encodes the provided value using gob. value must be a pointer.
type LocalCache ¶
type LocalCache struct { Cache *bigcache.BigCache Encoder CacheEncoder Metrics CacheMetrics TracingEnabled bool }
LocalCache defines a remote-caching approach in which keys are stored remotely in a separate process.
func (LocalCache) Delete ¶
func (lc LocalCache) Delete(ctx context.Context, key string) error
Delete removes the value from local cache
func (LocalCache) Get ¶
func (lc LocalCache) Get(ctx context.Context, key string, target interface{}) error
Get retrieves the value from cache, decodes it, and sets the result in target. target must be a pointer.
func (LocalCache) Purge ¶
func (lc LocalCache) Purge(ctx context.Context) error
Purge wipes out all items in local cache
type LocalCacheConfig ¶
type LocalCacheConfig struct { Eviction time.Duration TTL time.Duration Shards uint // Must be power of 2 TracingEnabled bool }
LocalCacheConfig is the necessary configuration for instantiating a LocalCache struct
func (LocalCacheConfig) NewCache ¶
func (lcc LocalCacheConfig) NewCache( encoder CacheEncoder, metrics CacheMetrics, ) (LocalCache, error)
NewCache constructs and returns a LocalCache given configuration
func (*LocalCacheConfig) RegisterFlags ¶
func (lcc *LocalCacheConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers LocalCache pflags
type MockCache ¶
type MockCache struct { Cache map[string][]byte Encoder CacheEncoder Metrics CacheMetrics }
MockCache mocks the Cache implementation for use in test caches
func NewMockCache ¶
func NewMockCache(encoder CacheEncoder) *MockCache
NewMockCache constructs a new cache for testing
type MockCacheEncoder ¶
type MockCacheEncoder struct{}
MockCacheEncoder is a fake encoder for use in tests
func (MockCacheEncoder) Decode ¶
func (mce MockCacheEncoder) Decode(cachedValue []byte, target interface{}) error
Decode mock returns no error
func (MockCacheEncoder) Encode ¶
func (mce MockCacheEncoder) Encode(value interface{}) ([]byte, error)
Encode mock simply returns the value it was given
type MockCacheMetrics ¶
MockCacheMetrics provides a mock cache metrics implementation
func (*MockCacheMetrics) DeleteHit ¶
func (mcc *MockCacheMetrics) DeleteHit()
DeleteHit is a mock metrics DeleteHit implementation
func (*MockCacheMetrics) DeleteMiss ¶
func (mcc *MockCacheMetrics) DeleteMiss()
DeleteMiss is a mock metrics DeleteMiss implementation
func (*MockCacheMetrics) Hit ¶
func (mcc *MockCacheMetrics) Hit()
Hit is a mock metrics Hit implementation
func (*MockCacheMetrics) Miss ¶
func (mcc *MockCacheMetrics) Miss()
Miss is a mock metrics Miss implementation
func (*MockCacheMetrics) PurgeHit ¶
func (mcc *MockCacheMetrics) PurgeHit()
PurgeHit is a mock metrics PurgeHit implementation
func (*MockCacheMetrics) PurgeMiss ¶
func (mcc *MockCacheMetrics) PurgeMiss()
PurgeMiss is a mock metrics PurgeMiss implementation
func (*MockCacheMetrics) Set ¶
func (mcc *MockCacheMetrics) Set()
Set is a mock metrics Set implementation
func (*MockCacheMetrics) SetCollision ¶
func (mcc *MockCacheMetrics) SetCollision()
SetCollision is a mock metrics SetCollision implementation
type MockTieredCacheCreator ¶
MockTieredCacheCreator provides a mock tiered cache config implementation
func (*MockTieredCacheCreator) NewCache ¶
func (m *MockTieredCacheCreator) NewCache( encoder CacheEncoder, metrics CacheMetrics, localMetrics CacheMetrics, remoteMetrics CacheMetrics, ) (Cache, error)
NewCache returns a mocked tiered cache
type MockedCacheEncoder ¶
MockCacheEncoder mocks the cache encoder for use in tests
func (*MockedCacheEncoder) Decode ¶
func (mce *MockedCacheEncoder) Decode(cachedValue []byte, target interface{}) error
Decode mocks the cache decode implementation
func (*MockedCacheEncoder) Encode ¶
func (mce *MockedCacheEncoder) Encode(value interface{}) ([]byte, error)
Encode mocks the cache encode implementation
type PrometheusCacheMetrics ¶
type PrometheusCacheMetrics struct {
// contains filtered or unexported fields
}
PrometheusCacheMetrics surfaces cache metrics for usage with Prometheus
func NewPrometheusCacheMetrics ¶
func NewPrometheusCacheMetrics(client, cacheName string) *PrometheusCacheMetrics
NewPrometheusCacheMetrics creates and returns a Prometheus cache metrics recorder
func (*PrometheusCacheMetrics) DeleteHit ¶
func (pcm *PrometheusCacheMetrics) DeleteHit()
DeleteHit defines a deletion hit from cache
func (*PrometheusCacheMetrics) DeleteMiss ¶
func (pcm *PrometheusCacheMetrics) DeleteMiss()
DeleteMiss defines a deletion miss from cache
func (*PrometheusCacheMetrics) Hit ¶
func (pcm *PrometheusCacheMetrics) Hit()
Hit defines a cache hit
func (*PrometheusCacheMetrics) Miss ¶
func (pcm *PrometheusCacheMetrics) Miss()
Miss defines a cache miss
func (*PrometheusCacheMetrics) PurgeHit ¶
func (pcm *PrometheusCacheMetrics) PurgeHit()
PurgeHit defines a purge hit of cache
func (*PrometheusCacheMetrics) PurgeMiss ¶
func (pcm *PrometheusCacheMetrics) PurgeMiss()
PurgeMiss defines a purge miss of cache
func (*PrometheusCacheMetrics) Set ¶
func (pcm *PrometheusCacheMetrics) Set()
Set defines a cache set
func (*PrometheusCacheMetrics) SetCollision ¶
func (pcm *PrometheusCacheMetrics) SetCollision()
SetCollision defines a cache set collision
type RemoteCache ¶
type RemoteCache struct { Encoder CacheEncoder Metrics CacheMetrics TracingEnabled bool // contains filtered or unexported fields }
RemoteCache defines a remote-caching approach in which keys are stored remotely in a separate process.
func (RemoteCache) Close ¶
func (rc RemoteCache) Close()
Close cleans up cache and removes any open connections
func (RemoteCache) Delete ¶
func (rc RemoteCache) Delete(ctx context.Context, key string) error
Delete removes the value from remote cache. Because Redis doesnt support Fuzzy matches for delete, this function first gets all matching keys, and then proceeds to pipeline deletion of those keys
func (RemoteCache) Get ¶
func (rc RemoteCache) Get(ctx context.Context, key string, target interface{}) error
Get retrieves the value from cache, decodes it, and sets the result in target. target must be a pointer.
func (RemoteCache) Purge ¶
func (rc RemoteCache) Purge(ctx context.Context) error
Purge wipes out all items under control of this cache in Redis
type RemoteCacheConfig ¶
type RemoteCacheConfig struct { URLs []string AuthToken string Timeout time.Duration TracingEnabled bool }
RemoteCacheConfig is the necessary configuration for instantiating a RemoteCache struct
func (RemoteCacheConfig) NewCache ¶
func (rcc RemoteCacheConfig) NewCache( encoder CacheEncoder, metrics CacheMetrics, ) (RemoteCache, error)
NewCache constructs and returns a RemoteCache given configuration
func (*RemoteCacheConfig) RegisterFlags ¶
func (rcc *RemoteCacheConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers RemoteCache pflags
type TieredCache ¶
type TieredCache struct { Remote Cache Local Cache Metrics CacheMetrics TracingEnabled bool }
TieredCache defines a combined local and remote-caching approach in which keys are stored remotely in a separate process as well as cached locally. Local cache is preferred.
func (TieredCache) Close ¶
func (tc TieredCache) Close()
Close cleans up cache and removes any open connections
func (TieredCache) Delete ¶
func (tc TieredCache) Delete(ctx context.Context, key string) error
Delete removes the value from local cache and remote cache
func (TieredCache) Get ¶
func (tc TieredCache) Get(ctx context.Context, key string, target interface{}) error
Get retrieves the value from the tiered cache, cache, decodes it, and sets the result in target. Local cache first, then remote. target must be a pointer.
func (TieredCache) GetBytes ¶
GetBytes gets the requested bytes from from tiered cache. Local first, then remote.
func (TieredCache) Purge ¶
func (tc TieredCache) Purge(ctx context.Context) error
Purge wipes out all items locally, and all items under control of this cache in Redis
type TieredCacheConfig ¶
type TieredCacheConfig struct { RemoteConfig RemoteCacheConfig LocalConfig LocalCacheConfig Encoder CacheEncoder TracingEnabled bool }
TieredCacheConfig is the necessary configuration for instantiating a TieredCache struct
func (TieredCacheConfig) NewCache ¶
func (tcc TieredCacheConfig) NewCache( encoder CacheEncoder, metrics CacheMetrics, localMetrics CacheMetrics, remoteMetrics CacheMetrics, ) (Cache, error)
NewCache constructs and returns a TieredCache given configuration
func (*TieredCacheConfig) RegisterFlags ¶
func (tcc *TieredCacheConfig) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers TieredCache pflags
type TieredCacheCreator ¶
type TieredCacheCreator interface { NewCache( encoder CacheEncoder, metrics CacheMetrics, localMetrics CacheMetrics, remoteMetrics CacheMetrics, ) (Cache, error) }
TieredCacheCreator defines an interface to create and return a Tiered Cache