Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MutationCache ¶
type MutationCache interface {
GetByKey(key string) (interface{}, bool, error)
ByIndex(indexName, indexKey string) ([]interface{}, error)
Mutation(interface{})
OnAddOrUpdate(obj runtime.Object)
OnDelete(obj runtime.Object)
// contains filtered or unexported methods
}
MutationCache is able to take the result of update operations and stores them in an LRU that can be used to provide a more current view of a requested object. It requires interpreting resourceVersions for comparisons. Implementations must be thread-safe. OnAddOrupdate and OnDelete should be called from informer event handlers to increase the accuracy of the cache.
func NewIntegerResourceVersionMutationCache ¶
func NewIntegerResourceVersionMutationCache(logger klog.Logger, keyFunc cache.KeyFunc, backingCache Store, indexer Indexer, ttl time.Duration, includeAdds bool) MutationCache
NewIntegerResourceVersionMutationCache is like NewIntegerResourceVersionMutationCacheWithOptions with a fixed cache size of 100.
func NewIntegerResourceVersionMutationCacheWithOptions ¶ added in v0.34.0
func NewIntegerResourceVersionMutationCacheWithOptions(logger klog.Logger, keyFunc cache.KeyFunc, backingCache Store, options MutationCacheOptions) MutationCache
NewIntegerResourceVersionMutationCacheWithOptions returns a MutationCache that understands how to deal with objects that have a resource version that:
- is an integer
- increases when updated
- is comparable across the same resource in a namespace
Most backends will have these semantics. Indexer may be nil. ttl controls how long an item remains in the mutation cache before it is removed.
If includeAdds is true, objects in the mutation cache will be returned even if they don't exist in the underlying store. This is only safe if your use of the cache can handle mutation entries remaining in the cache for up to ttl when mutations and deletes occur very closely in time.
Note that this also applies to objects updated by the caller, not just objects added by it. That's because the MutationCache may hold an updated object at a time when the underlying store already removed it because it was deleted in the apiserver after the update. To address this, the caller can call OnAddOrUpdate and OnDelete from informer event handlers.
This informs the MutationCache about all changes observed by the store and enables it to remove a locally added or updated object immediately once it appears in the store, which prevents the "stale updated object" problem.
This does not solve the "stale added object" problem reliably because the informer might never see the added object when the add is followed quickly by a delete. The caller has to handle stale added objects by checking whether they still exist once the TTL is over.
type MutationCacheOptions ¶ added in v0.34.0
type MutationCacheOptions struct {
// Indexer is used by ByIndex to look up objects. May be nil, in which case ByIndex returns an error.
Indexer Indexer
// TTL controls how long an item remains in the mutation cache before it is removed.
// Zero means the default of 5 minutes.
TTL time.Duration
// IncludeAdds makes the cache return objects even if they don't exist
// in the underlying store. This is only safe if your use of the cache
// can handle mutation entries remaining in the cache for up to TTL
// when mutations and deletes occur very closely in time.
IncludeAdds bool
// MaxCacheSize limits how many mutated objects are tracked; the least
// recently used entries are evicted once the limit is reached.
// Zero means the default of 100.
MaxCacheSize int
}
MutationCacheOptions configures the MutationCache returned by NewIntegerResourceVersionMutationCacheWithOptions.
type ResourceVersionComparator ¶
ResourceVersionComparator is able to compare object versions.