Documentation
¶
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Delete(cq CacheQuery)
- func (c *Cache) GetMinWaitTime() time.Duration
- func (c *Cache) Purge(before time.Time) PurgeStats
- func (c *Cache) Search(cq CacheQuery) ([]*sdp.Item, error)
- func (c *Cache) StartPurger(ctx context.Context) error
- func (c *Cache) StoreError(err error, duration time.Duration, cacheQuery CacheQuery)
- func (c *Cache) StoreItem(item *sdp.Item, duration time.Duration)
- type CacheQuery
- type CachedResult
- type IndexValues
- type PurgeStats
- type SST
- type SSTHash
Constants ¶
const MinWaitDefault = (5 * time.Second)
MinWaitDefault The default minimum wait time
Variables ¶
var ErrCacheNotFound = errors.New("not found in cache")
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// Minimum amount of time to wait between cache purges
MinWaitTime time.Duration
// contains filtered or unexported fields
}
func (*Cache) Delete ¶
func (c *Cache) Delete(cq CacheQuery)
Delete Deletes anything that matches the given cache query
func (*Cache) GetMinWaitTime ¶
GetMinWaitTime Returns the minimum wait time or the default if not set
func (*Cache) Purge ¶
func (c *Cache) Purge(before time.Time) PurgeStats
Purge Purges all expired items from the cache. The user must pass in the `before` time. All items that expired before this will be purged. Usually this would be just `time.Now()` however it could be overridden for testing
func (*Cache) Search ¶
func (c *Cache) Search(cq CacheQuery) ([]*sdp.Item, error)
Search Runs a given query against the cache. If a cached error is found it will be returned immediately, if nothing is found a ErrCacheNotFound will be returned. Otherwise this will return items that match ALL of the given query parameters
func (*Cache) StartPurger ¶
StartPurger Starts the purge process in the background, it will be cancelled when the context is cancelled. The cache will be purged initially, at which point the process will sleep until the next time an item expires
func (*Cache) StoreError ¶
func (c *Cache) StoreError(err error, duration time.Duration, cacheQuery CacheQuery)
StoreError Stores an error for the given duration. Since we can't determine the index values from the error itself, the user also needs to pass in the cache query that this error should respond to
type CacheQuery ¶ added in v0.5.1
type CacheQuery struct {
SST SST // *required
UniqueAttributeValue *string
Method *sdp.RequestMethod
Query *string
}
func (CacheQuery) Matches ¶ added in v0.5.1
func (cq CacheQuery) Matches(i IndexValues) bool
Matches Returns whether or not the supplied index values match the CacheQuery, excluding the SST since this will have already been validated. Note that this only checks values that ave actually been set in the CacheQuery
func (CacheQuery) String ¶ added in v0.5.1
func (cq CacheQuery) String() string
func (CacheQuery) ToIndexValues ¶ added in v0.5.1
func (cq CacheQuery) ToIndexValues() IndexValues
ToIndexValues Converts a cache query to a set of index values
type CachedResult ¶
type CachedResult struct {
// Item is the actual cached item
Item *sdp.Item
// Error is the error that we want
Error error
// The time at which this item expires
Expiry time.Time
// Values that we use for calculating indexes
IndexValues IndexValues
}
CachedResult An item including cache metadata
type IndexValues ¶ added in v0.5.1
type IndexValues struct {
SSTHash SSTHash
UniqueAttributeValue string
Method sdp.RequestMethod
Query string
}
type PurgeStats ¶
type PurgeStats struct {
// How many items were timed out of the cache
NumPurged int
// How long purging took overall
TimeTaken time.Duration
// The expiry time of the next item to expire. If there are no more items in
// the cache, this will be nil
NextExpiry *time.Time
}
PurgeStats Stats about the Purge