Documentation ¶
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) Clear()
- func (c *Cache) Delete(ck CacheKey)
- func (c *Cache) GetMinWaitTime() time.Duration
- func (c *Cache) Lookup(ctx context.Context, srcName string, method sdp.QueryMethod, scope string, ...) (bool, CacheKey, []*sdp.Item, *sdp.QueryError)
- func (c *Cache) Purge(before time.Time) PurgeStats
- func (c *Cache) Search(ck CacheKey) ([]*sdp.Item, error)
- func (c *Cache) StartPurger(ctx context.Context) error
- func (c *Cache) StoreError(err error, duration time.Duration, cacheQuery CacheKey)
- func (c *Cache) StoreItem(item *sdp.Item, duration time.Duration, ck CacheKey)
- type CacheKey
- 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) GetMinWaitTime ¶
GetMinWaitTime Returns the minimum wait time or the default if not set
func (*Cache) Lookup ¶ added in v0.5.3
func (c *Cache) Lookup(ctx context.Context, srcName string, method sdp.QueryMethod, scope string, typ string, query string, ignoreCache bool) (bool, CacheKey, []*sdp.Item, *sdp.QueryError)
Lookup returns true/false whether or not the cache has a result for the given query. If there are results, they will be returned as slice of `sdp.Item`s or an `*sdp.QueryError`. The CacheKey is always returned, even if the lookup otherwise fails or errors
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 ¶
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 ¶
StoreError Stores an error for the given duration.
type CacheKey ¶ added in v0.5.3
type CacheKey struct { SST SST // *required UniqueAttributeValue *string Method *sdp.QueryMethod Query *string }
func CacheKeyFromParts ¶ added in v0.5.3
func CacheKeyFromQuery ¶ added in v0.5.3
func (CacheKey) Matches ¶ added in v0.5.3
func (ck CacheKey) 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 (CacheKey) ToIndexValues ¶ added in v0.5.3
func (ck CacheKey) 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 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