Documentation ¶
Index ¶
- Constants
- type Cache
- func (c Cache) Add(key string, value interface{}, expiration time.Duration) error
- func (c Cache) Clear()
- func (c Cache) Delete(key string)
- func (c Cache) DeleteExpired()
- func (c Cache) Get(key string) (interface{}, bool)
- func (c Cache) GetExpiration(key string) time.Duration
- func (c Cache) HasExpired(key string) bool
- func (c Cache) ItemCount() int
- func (c Cache) Set(key string, value interface{}, expiration time.Duration) error
- func (c Cache) SetExpiration(key string, expiration time.Duration)
- type CacheRecorder
- type Item
Constants ¶
const ( // CacheEventTypeMiss is the event type for cache misses. CacheEventTypeMiss = "cache_miss" // CacheEventTypeHit is the event type for cache hits. CacheEventTypeHit = "cache_hit" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe in-memory key/value store.
func (Cache) Add ¶
Add an item to the cache, existing items will not be overwritten. To overwrite existing items, use Set. If the cache is full, Add will return an error.
func (Cache) Clear ¶
func (c Cache) Clear()
Clear all items from the cache. This reallocates the underlying array holding the items, so that the memory used by the items is reclaimed.
func (Cache) Delete ¶
func (c Cache) Delete(key string)
Delete an item from the cache. Does nothing if the key is not in the cache.
func (Cache) DeleteExpired ¶
func (c Cache) DeleteExpired()
DeleteExpired deletes all expired items from the cache.
func (Cache) Get ¶
Get an item from the cache. Returns the item or nil, and a bool indicating whether the key was found.
func (Cache) GetExpiration ¶
GetExpiration returns the expiration for the given key. Returns zero if the key is not in the cache or the item has already expired.
func (Cache) HasExpired ¶
HasExpired returns true if the item has expired.
func (Cache) ItemCount ¶
func (c Cache) ItemCount() int
ItemCount returns the number of items in the cache. This may include items that have expired, but have not yet been cleaned up.
func (Cache) Set ¶
Set adds an item to the cache, replacing any existing item. If expiration is zero, the item never expires. If the cache is full, Set will return an error.
func (Cache) SetExpiration ¶
SetExpiration sets the expiration for the given key. Does nothing if the key is not in the cache.
type CacheRecorder ¶ added in v0.24.0
type CacheRecorder struct {
// contains filtered or unexported fields
}
CacheRecorder is a recorder for cache events.
func MustMakeMetrics ¶ added in v0.24.0
func MustMakeMetrics() *CacheRecorder
MustMakeMetrics creates a new CacheRecorder, and registers the metrics collectors in the controller-runtime metrics registry.
func NewCacheRecorder ¶ added in v0.24.0
func NewCacheRecorder() *CacheRecorder
NewCacheRecorder returns a new CacheRecorder. The configured labels are: event_type, name, namespace. The event_type is one of:
- "miss"
- "hit"
- "update"
The name is the name of the reconciled resource. The namespace is the namespace of the reconciled resource.
func (*CacheRecorder) Collectors ¶ added in v0.24.0
func (r *CacheRecorder) Collectors() []prometheus.Collector
Collectors returns the metrics.Collector objects for the CacheRecorder.
func (*CacheRecorder) DeleteCacheEvent ¶ added in v1.1.0
func (r *CacheRecorder) DeleteCacheEvent(event, name, namespace string)
DeleteCacheEvent deletes the cache event metric.
func (*CacheRecorder) IncCacheEvents ¶ added in v0.24.0
func (r *CacheRecorder) IncCacheEvents(event, name, namespace string)
IncCacheEventCount increment by 1 the cache event count for the given event type, name and namespace.