Documentation
¶
Index ¶
- Constants
- type Cache
- func (c *Cache) BulkStoreItem(items []*sdp.Item, duration time.Duration, tags Tags)
- func (c *Cache) Clear()
- func (c *Cache) Delete(searchTags Tags) error
- func (c *Cache) GetMinWaitTime() time.Duration
- func (c *Cache) Purge() PurgeStats
- func (c *Cache) Search(searchTags Tags) ([]*sdp.Item, error)
- func (c *Cache) StartPurger()
- func (c *Cache) StopPurger()
- func (c *Cache) StoreError(err error, duration time.Duration, tags Tags)
- func (c *Cache) StoreItem(item *sdp.Item, duration time.Duration, tags Tags)
- type CacheNotFoundError
- type CachedResult
- type PurgeStats
- type Tags
Constants ¶
const MinWaitDefault = (5 * time.Second)
MinWaitDefault The default minimum wait time
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// Name used for logging since there are many caches
Name string
Storage []CachedResult
// The minimum amount of time to wait between purges, defaults to
// MinWaitDefault
MinWaitTime time.Duration
// contains filtered or unexported fields
}
Cache is responsible for caching data between calls
func (*Cache) BulkStoreItem ¶
BulkStoreItem stores many items at once instead of just one
func (*Cache) GetMinWaitTime ¶
GetMinWaitTime Returns the minimum wait time or the default if not set
func (*Cache) Search ¶
Search will find all items with a given set of tags. If multiple tags are supplied an AND is used. If a cached error is found with matching tags it will be returned immediately
func (*Cache) StartPurger ¶
func (c *Cache) StartPurger()
StartPurger Starts the automatic purging of the cache
func (*Cache) StopPurger ¶ added in v0.3.0
func (c *Cache) StopPurger()
StopPurger Stops the cache purging goroutine
func (*Cache) StoreError ¶
StoreError Store an item in the cache.
Note that all errors will get the following tags by default:
isError: true
func (*Cache) StoreItem ¶
StoreItem Store an item in the cache.
Note that all stored items will have the following default tags applied:
type: (item.Type) context: (item.Context) uniqueAttributeValue: (item.Attributes[item.UniqueAttribute])
These default tags mean that each full tag set will be unique to an item
type CacheNotFoundError ¶
type CacheNotFoundError Tags
CacheNotFoundError is returned when an item is not found in the cache. Usually this would be handled very gracefully
func (CacheNotFoundError) Error ¶
func (c CacheNotFoundError) Error() string
type CachedResult ¶
type CachedResult struct {
// Item is the actual cached item
Item *sdp.Item
// Error is the error that we want
Error error
// CacheDuration How long to cache the item for
CacheDuration time.Duration
// InterstTime When the item was inserted into the cache
InsertTime time.Time
// Tags are arbitrary strings maps that can be searched on
Tags Tags
}
CachedResult An itemincluding cache metadata
func (*CachedResult) Expired ¶
func (cr *CachedResult) Expired() bool
Expired Tells us if the item's cache has expired
func (*CachedResult) HasTag ¶
func (cr *CachedResult) HasTag(key string, value string) bool
HasTag returns a boolean if the CachedResult has a given tag with a given value
func (*CachedResult) HasTags ¶
func (cr *CachedResult) HasTags(tags Tags) bool
HasTags returns whether a given result has all of the tags supplied. This is a logical AND query
type PurgeStats ¶
type PurgeStats struct {
// How many items were timed out of the cache
NumPurged int
// How long the Purgeing took overall
TimeTaken time.Duration
// Shortest cache duration of the remaining items
ShortestCacheRemaining time.Duration
}
PurgeStats Stats about the Purge
type Tags ¶
Tags A map of key-value pairs that can be searched on
func DefaultErrorTags ¶
DefaultErrorTags Returns default tags for any error
func DefaultItemTags ¶
DefaultItemTags Returns default tags for a given item