type MutationCache … type ResourceVersionComparator … // NewIntegerResourceVersionMutationCache 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. func NewIntegerResourceVersionMutationCache(backingCache Store, indexer Indexer, ttl time.Duration, includeAdds bool) MutationCache { … } type mutationCache … // GetByKey is never guaranteed to return back the value set in Mutation. It could be paged out, it could // be older than another copy, the backingCache may be more recent or, you might have written twice into the same key. // You get a value that was valid at some snapshot of time and will always return the newer of backingCache and mutationCache. func (c *mutationCache) GetByKey(key string) (interface{ … } // ByIndex returns the newer objects that match the provided index and indexer key. // Will return an error if no indexer was provided. func (c *mutationCache) ByIndex(name string, indexKey string) ([]interface{ … } // newerObject checks the mutation cache for a newer object and returns one if found. If the // mutated object is older than the backing object, it is removed from the Must be // called while the lock is held. func (c *mutationCache) newerObject(key string, backing runtime.Object) runtime.Object { … } // Mutation adds a change to the cache that can be returned in GetByKey if it is newer than the backingCache // copy. If you call Mutation twice with the same object on different threads, one will win, but its not defined // which one. This doesn't affect correctness, since the GetByKey guaranteed of "later of these two caches" is // preserved, but you may not get the version of the object you want. The object you get is only guaranteed to // "one that was valid at some point in time", not "the one that I want". func (c *mutationCache) Mutation(obj interface{ … } type etcdObjectVersioner … // ObjectResourceVersion implements Versioner func (a etcdObjectVersioner) ObjectResourceVersion(obj runtime.Object) (uint64, error) { … } // CompareResourceVersion compares etcd resource versions. Outside this API they are all strings, // but etcd resource versions are special, they're actually ints, so we can easily compare them. func (a etcdObjectVersioner) CompareResourceVersion(lhs, rhs runtime.Object) int { … }