Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
func New ¶
func New(expirationTime time.Duration, name string, metrics metrics.Metrics) (*Cache, error)
New creates a cache where items are evicted after being present for `expirationTime`. `name` is used to name the gauge used for metrics reporting.
func (*Cache) GetOrRetrieve ¶
func (c *Cache) GetOrRetrieve(ctx context.Context, key string, retriever Retriever) (interface{}, error)
GetOrRetrieve will return the cached value and if it isn't present will call `Retriever`. It is guaranteed there will only on one concurrent call to `Retriever` for each key, other accesses to the key will be blocked until `Retriever.Call` returns. If `Retriever.Call` fails the error will not be cached and subsequent calls will call the `Retriever` again.
type Retriever ¶
type Retriever interface {
// Call method called when a cache miss happens which will return the actual value that needs to be cached
Call(ctx context.Context, key string) (interface{}, error)
}
type RetrieverFunc ¶
type RetrieverFunc func(context.Context, string) (interface{}, error)
Click to show internal directories.
Click to hide internal directories.