Documentation ¶
Index ¶
- type CacheLayer
- type InMemoryCacheLayer
- func (layer *InMemoryCacheLayer) Delete(key string) error
- func (layer *InMemoryCacheLayer) Get(key string) (io.ReadCloser, time.Duration, error)
- func (layer *InMemoryCacheLayer) Refresh(key string, ttl time.Duration) error
- func (layer *InMemoryCacheLayer) Set(key string, entry io.ReadCloser, ttl time.Duration) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CacheLayer ¶
type CacheLayer interface { //Get requests a stored object from the cache with the cache key 'key'. // If there is no response with that key nil should be returned // If there is a response the response and the TTL should be returned // Error should only be returned in case of a error while getting the data like a connection error to a storage backend Get(key string) (io.ReadCloser, time.Duration, error) //Set a new cache entry. if a key is already in use it should be overwritten. Set(key string, entry io.ReadCloser, ttl time.Duration) error //Update the ttl of a existing cache entry Refresh(key string, ttl time.Duration) error //Delete a cache entry with the given key Delete(key string) error }
A CacheLayer stores and retrives cached responses. The cache may delete a entry at any point which is required by some cache replacement policies The TTL of a cached entry is a guide which can be used by the cache replacement policy It is recommended to keep stale content for as long as capacity of the storage backend allows
All actions of a cache layer must be safe for concurrent use by multiple goroutines.
type InMemoryCacheLayer ¶
type InMemoryCacheLayer struct { //Maximum size of the cache in bytes MaxSize int // contains filtered or unexported fields }
The InMemoryCacheLayer stores responses in memory This is a simple example without advanced features
func NewInMemoryCacheLayer ¶
func NewInMemoryCacheLayer(maxSize int) *InMemoryCacheLayer
func (*InMemoryCacheLayer) Delete ¶
func (layer *InMemoryCacheLayer) Delete(key string) error
func (*InMemoryCacheLayer) Get ¶
func (layer *InMemoryCacheLayer) Get(key string) (io.ReadCloser, time.Duration, error)
func (*InMemoryCacheLayer) Refresh ¶
func (layer *InMemoryCacheLayer) Refresh(key string, ttl time.Duration) error
func (*InMemoryCacheLayer) Set ¶
func (layer *InMemoryCacheLayer) Set(key string, entry io.ReadCloser, ttl time.Duration) error
Click to show internal directories.
Click to hide internal directories.