{"modulePath":"github.com/unitytech/client-go","version":"v11.0.0+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cache\n\nPackage cache is a client-side caching mechanism. It is useful for reducing the number of server calls you'd otherwise need to make. Reflector watches a server and updates a Store. Two stores are provided; one that simply caches objects (for example, to allow a scheduler to list currently available nodes), and one that additionally acts as a FIFO queue (for example, to allow a scheduler to process incoming pods).\n\n## Constants\n\n```go\nconst (\n\tNamespaceIndex string = \"namespace\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrZeroLengthDeltasObject is returned in a KeyError if a Deltas\n\t// object with zero length is encountered (should be impossible,\n\t// but included for completeness).\n\tErrZeroLengthDeltasObject = errors.New(\"0 length Deltas object; can't get key\")\n)\n```\n\n```go\nvar FIFOClosedError error = errors.New(\"DeltaFIFO: manipulating with closed queue\")\n```\n\n## Functions\n\n```go\nfunc DeletionHandlingMetaNamespaceKeyFunc(obj interface{}) (string, error)\n```\nDeletionHandlingMetaNamespaceKeyFunc checks for DeletedFinalStateUnknown objects before calling MetaNamespaceKeyFunc.\n\n```go\nfunc ListAll(store Store, selector labels.Selector, appendFn AppendFunc) error\n```\n\n```go\nfunc ListAllByNamespace(indexer Indexer, namespace string, selector labels.Selector, appendFn AppendFunc) error\n```\n\n```go\nfunc MetaNamespaceIndexFunc(obj interface{}) ([]string, error)\n```\nMetaNamespaceIndexFunc is a default index function that indexes based on an object's namespace\n\n```go\nfunc MetaNamespaceKeyFunc(obj interface{}) (string, error)\n```\nMetaNamespaceKeyFunc is a convenient default KeyFunc which knows how to make keys for API objects which implement meta.Interface. The key uses the format \\\u003cnamespace\u003e/\\\u003cname\u003e unless \\\u003cnamespace\u003e is empty, then it's just \\\u003cname\u003e.\n\nTODO: replace key-as-string with a key-as-struct so that this packing/unpacking won't be necessary.\n\n```go\nfunc NewIndexerInformer(\n\tlw ListerWatcher,\n\tobjType runtime.Object,\n\tresyncPeriod time.Duration,\n\th ResourceEventHandler,\n\tindexers Indexers,\n) (Indexer, Controller)\n```\nNewIndexerInformer returns a Indexer and a controller for populating the index while also providing event notifications. You should only used the returned Index for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty.\n\nParameters:\n\n  - lw is list and watch functions for the source of the resource you want to be informed of.\n  - objType is an object of the type that you expect to receive.\n  - resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller).\n  - h is the object you want notifications sent to.\n  - indexers is the indexer for the received object type.\n\n```go\nfunc NewInformer(\n\tlw ListerWatcher,\n\tobjType runtime.Object,\n\tresyncPeriod time.Duration,\n\th ResourceEventHandler,\n) (Store, Controller)\n```\nNewInformer returns a Store and a controller for populating the store while also providing event notifications. You should only used the returned Store for Get/List operations; Add/Modify/Deletes will cause the event notifications to be faulty.\n\nParameters:\n\n  - lw is list and watch functions for the source of the resource you want to be informed of.\n  - objType is an object of the type that you expect to receive.\n  - resyncPeriod: if non-zero, will re-list this often (you will get OnUpdate calls, even if nothing changed). Otherwise, re-list will be delayed as long as possible (until the upstream source closes the watch or times out, or you stop the controller).\n  - h is the object you want notifications sent to.\n\n```go\nfunc NewNamespaceKeyedIndexerAndReflector(lw ListerWatcher, expectedType interface{}, resyncPeriod time.Duration) (indexer Indexer, reflector *Reflector)\n```\nNewNamespaceKeyedIndexerAndReflector creates an Indexer and a Reflector The indexer is configured to key on namespace\n\n```go\nfunc Pop(queue Queue) interface{}\n```\nHelper function for popping from Queue. WARNING: Do NOT use this function in non-test code to avoid races unless you really really really really know what you are doing.\n\n```go\nfunc SetReflectorMetricsProvider(metricsProvider MetricsProvider)\n```\nSetReflectorMetricsProvider sets the metrics provider\n\n```go\nfunc SplitMetaNamespaceKey(key string) (namespace, name string, err error)\n```\nSplitMetaNamespaceKey returns the namespace and name that MetaNamespaceKeyFunc encoded into key.\n\nTODO: replace key-as-string with a key-as-struct so that this packing/unpacking won't be necessary.\n\n```go\nfunc WaitForCacheSync(stopCh \u003c-chan struct{}, cacheSyncs ...InformerSynced) bool\n```\nWaitForCacheSync waits for caches to populate.  It returns true if it was successful, false if the controller should shutdown\n\n## Types\n\n```go\ntype AppendFunc func(interface{})\n```\nAppendFunc is used to add a matching item to whatever list the caller is using\n\n```go\ntype CacheMutationDetector interface {\n\tAddObject(obj interface{})\n\tRun(stopCh \u003c-chan struct{})\n}\n```\n\n```go\nfunc NewCacheMutationDetector(name string) CacheMutationDetector\n```\n\n```go\ntype Config struct {\n\t// The queue for your objects - has to be a DeltaFIFO due to\n\t// assumptions in the implementation. Your Process() function\n\t// should accept the output of this Queue's Pop() method.\n\tQueue\n\n\t// Something that can list and watch your objects.\n\tListerWatcher\n\n\t// Something that can process your objects.\n\tProcess ProcessFunc\n\n\t// The type of your objects.\n\tObjectType runtime.Object\n\n\t// Reprocess everything at least this often.\n\t// Note that if it takes longer for you to clear the queue than this\n\t// period, you will end up processing items in the order determined\n\t// by FIFO.Replace(). Currently, this is random. If this is a\n\t// problem, we can change that replacement policy to append new\n\t// things to the end of the queue instead of replacing the entire\n\t// queue.\n\tFullResyncPeriod time.Duration\n\n\t// ShouldResync, if specified, is invoked when the controller's reflector determines the next\n\t// periodic sync should occur. If this returns true, it means the reflector should proceed with\n\t// the resync.\n\tShouldResync ShouldResyncFunc\n\n\t// If true, when Process() returns an error, re-enqueue the object.\n\t// TODO: add interface to let you inject a delay/backoff or drop\n\t//       the object completely if desired. Pass the object in\n\t//       question to this interface as a parameter.\n\tRetryOnError bool\n}\n```\nConfig contains all the settings for a Controller.\n\n```go\ntype Controller interface {\n\tRun(stopCh \u003c-chan struct{})\n\tHasSynced() bool\n\tLastSyncResourceVersion() string\n}\n```\n\n```go\nfunc New(c *Config) Controller\n```\nNew makes a new Controller from the given Config.\n\n```go\ntype CounterMetric interface {\n\tInc()\n}\n```\nCounterMetric represents a single numerical value that only ever goes up.\n\n```go\ntype DeletedFinalStateUnknown struct {\n\tKey string\n\tObj interface{}\n}\n```\nDeletedFinalStateUnknown is placed into a DeltaFIFO in the case where an object was deleted but the watch deletion event was missed. In this case we don't know the final \"resting\" state of the object, so there's a chance the included \\`Obj\\` is stale.\n\n```go\ntype Delta struct {\n\tType   DeltaType\n\tObject interface{}\n}\n```\nDelta is the type stored by a DeltaFIFO. It tells you what change happened, and the object's state after\\* that change.\n\n\\[\\*] Unless the change is a deletion, and then you'll get the final\n\n\tstate of the object before it was deleted.\n\n```go\ntype DeltaFIFO struct {\n\t// contains filtered or unexported fields\n}\n```\nDeltaFIFO is like FIFO, but allows you to process deletes.\n\nDeltaFIFO is a producer-consumer queue, where a Reflector is intended to be the producer, and the consumer is whatever calls the Pop() method.\n\nDeltaFIFO solves this use case:\n\n  - You want to process every object change (delta) at most once.\n  - When you process an object, you want to see everything that's happened to it since you last processed it.\n  - You want to process the deletion of objects.\n  - You might want to periodically reprocess objects.\n\nDeltaFIFO's Pop(), Get(), and GetByKey() methods return interface{} to satisfy the Store/Queue interfaces, but it will always return an object of type Deltas.\n\nA note on threading: If you call Pop() in parallel from multiple threads, you could end up with multiple threads processing slightly different versions of the same object.\n\nA note on the KeyLister used by the DeltaFIFO: It's main purpose is to list keys that are \"known\", for the purpose of figuring out which items have been deleted when Replace() or Delete() are called. The deleted object will be included in the DeleteFinalStateUnknown markers. These objects could be stale.\n\n```go\nfunc NewDeltaFIFO(keyFunc KeyFunc, knownObjects KeyListerGetter) *DeltaFIFO\n```\nNewDeltaFIFO returns a Store which can be used process changes to items.\n\nkeyFunc is used to figure out what key an object should have. (It's exposed in the returned DeltaFIFO's KeyOf() method, with bonus features.)\n\n'keyLister' is expected to return a list of keys that the consumer of this queue \"knows about\". It is used to decide which items are missing when Replace() is called; 'Deleted' deltas are produced for these items. It may be nil if you don't need to detect all deletions. TODO: consider merging keyLister with this object, tracking a list of\n\n\t\"known\" keys when Pop() is called. Have to think about how that\n\taffects error retrying.\n\nNOTE: It is possible to misuse this and cause a race when using an\n\n\texternal known object source.\n\tWhether there is a potential race depends on how the comsumer\n\tmodifies knownObjects. In Pop(), process function is called under\n\tlock, so it is safe to update data structures in it that need to be\n\tin sync with the queue (e.g. knownObjects).\n\n\tExample:\n\tIn case of sharedIndexInformer being a consumer\n\t(https://github.com/kubernetes/kubernetes/blob/0cdd940f/staging/\n\tsrc/k8s.io/client-go/tools/cache/shared_informer.go#L192),\n\tthere is no race as knownObjects (s.indexer) is modified safely\n\tunder DeltaFIFO's lock. The only exceptions are GetStore() and\n\tGetIndexer() methods, which expose ways to modify the underlying\n\tstorage. Currently these two methods are used for creating Lister\n\tand internal tests.\n\nAlso see the comment on DeltaFIFO.\n\n```go\nfunc (f *DeltaFIFO) Add(obj interface{}) error\n```\nAdd inserts an item, and puts it in the queue. The item is only enqueued if it doesn't already exist in the set.\n\n```go\nfunc (f *DeltaFIFO) AddIfNotPresent(obj interface{}) error\n```\nAddIfNotPresent inserts an item, and puts it in the queue. If the item is already present in the set, it is neither enqueued nor added to the set.\n\nThis is useful in a single producer/consumer scenario so that the consumer can safely retry items without contending with the producer and potentially enqueueing stale items.\n\nImportant: obj must be a Deltas (the output of the Pop() function). Yes, this is different from the Add/Update/Delete functions.\n\n```go\nfunc (f *DeltaFIFO) Close()\n```\nClose the queue.\n\n```go\nfunc (f *DeltaFIFO) Delete(obj interface{}) error\n```\nDelete is just like Add, but makes an Deleted Delta. If the item does not already exist, it will be ignored. (It may have already been deleted by a Replace (re-list), for example.\n\n```go\nfunc (f *DeltaFIFO) Get(obj interface{}) (item interface{}, exists bool, err error)\n```\nGet returns the complete list of deltas for the requested item, or sets exists=false. You should treat the items returned inside the deltas as immutable.\n\n```go\nfunc (f *DeltaFIFO) GetByKey(key string) (item interface{}, exists bool, err error)\n```\nGetByKey returns the complete list of deltas for the requested item, setting exists=false if that list is empty. You should treat the items returned inside the deltas as immutable.\n\n```go\nfunc (f *DeltaFIFO) HasSynced() bool\n```\nReturn true if an Add/Update/Delete/AddIfNotPresent are called first, or an Update called first but the first batch of items inserted by Replace() has been popped\n\n```go\nfunc (f *DeltaFIFO) IsClosed() bool\n```\nChecks if the queue is closed\n\n```go\nfunc (f *DeltaFIFO) KeyOf(obj interface{}) (string, error)\n```\nKeyOf exposes f's keyFunc, but also detects the key of a Deltas object or DeletedFinalStateUnknown objects.\n\n```go\nfunc (f *DeltaFIFO) List() []interface{}\n```\nList returns a list of all the items; it returns the object from the most recent Delta. You should treat the items returned inside the deltas as immutable.\n\n```go\nfunc (f *DeltaFIFO) ListKeys() []string\n```\nListKeys returns a list of all the keys of the objects currently in the FIFO.\n\n```go\nfunc (f *DeltaFIFO) Pop(process PopProcessFunc) (interface{}, error)\n```\nPop blocks until an item is added to the queue, and then returns it.  If multiple items are ready, they are returned in the order in which they were added/updated. The item is removed from the queue (and the store) before it is returned, so if you don't successfully process it, you need to add it back with AddIfNotPresent(). process function is called under lock, so it is safe update data structures in it that need to be in sync with the queue (e.g. knownKeys). The PopProcessFunc may return an instance of ErrRequeue with a nested error to indicate the current item should be requeued (equivalent to calling AddIfNotPresent under the lock).\n\nPop returns a 'Deltas', which has a complete list of all the things that happened to the object (deltas) while it was sitting in the queue.\n\n```go\nfunc (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error\n```\nReplace will delete the contents of 'f', using instead the given map. 'f' takes ownership of the map, you should not reference the map again after calling this function. f's queue is reset, too; upon return, it will contain the items in the map, in no particular order.\n\n```go\nfunc (f *DeltaFIFO) Resync() error\n```\nResync will send a sync event for each item\n\n```go\nfunc (f *DeltaFIFO) Update(obj interface{}) error\n```\nUpdate is just like Add, but makes an Updated Delta.\n\n```go\ntype DeltaType string\n```\nDeltaType is the type of a change (addition, deletion, etc)\n\n```go\nconst (\n\tAdded   DeltaType = \"Added\"\n\tUpdated DeltaType = \"Updated\"\n\tDeleted DeltaType = \"Deleted\"\n\t// The other types are obvious. You'll get Sync deltas when:\n\t//  * A watch expires/errors out and a new list/watch cycle is started.\n\t//  * You've turned on periodic syncs.\n\t// (Anything that trigger's DeltaFIFO's Replace() method.)\n\tSync DeltaType = \"Sync\"\n)\n```\n\n```go\ntype Deltas []Delta\n```\nDeltas is a list of one or more 'Delta's to an individual object. The oldest delta is at index 0, the newest delta is the last one.\n\n```go\nfunc (d Deltas) Newest() *Delta\n```\nNewest is a convenience function that returns the newest delta, or nil if there are no deltas.\n\n```go\nfunc (d Deltas) Oldest() *Delta\n```\nOldest is a convenience function that returns the oldest delta, or nil if there are no deltas.\n\n```go\ntype ErrRequeue struct {\n\t// Err is returned by the Pop function\n\tErr error\n}\n```\nErrRequeue may be returned by a PopProcessFunc to safely requeue the current item. The value of Err will be returned from Pop.\n\n```go\nfunc (e ErrRequeue) Error() string\n```\n\n```go\ntype ExpirationCache struct {\n\t// contains filtered or unexported fields\n}\n```\nExpirationCache implements the store interface\n\n 1. All entries are automatically time stamped on insert a. The key is computed based off the original item/keyFunc b. The value inserted under that key is the timestamped item\n 2. Expiration happens lazily on read based on the expiration policy a. No item can be inserted into the store while we're expiring \\*any\\* item in the cache.\n 3. Time-stamps are stripped off unexpired entries before return\n\nNote that the ExpirationCache is inherently slower than a normal threadSafeStore because it takes a write lock every time it checks if an item has expired.\n\n```go\nfunc (c *ExpirationCache) Add(obj interface{}) error\n```\nAdd timestamps an item and inserts it into the cache, overwriting entries that might exist under the same key.\n\n```go\nfunc (c *ExpirationCache) Delete(obj interface{}) error\n```\nDelete removes an item from the cache.\n\n```go\nfunc (c *ExpirationCache) Get(obj interface{}) (interface{}, bool, error)\n```\nGet returns unexpired items. It purges the cache of expired items in the process.\n\n```go\nfunc (c *ExpirationCache) GetByKey(key string) (interface{}, bool, error)\n```\nGetByKey returns the item stored under the key, or sets exists=false.\n\n```go\nfunc (c *ExpirationCache) List() []interface{}\n```\nList retrieves a list of unexpired items. It purges the cache of expired items in the process.\n\n```go\nfunc (c *ExpirationCache) ListKeys() []string\n```\nListKeys returns a list of all keys in the expiration cache.\n\n```go\nfunc (c *ExpirationCache) Replace(list []interface{}, resourceVersion string) error\n```\nReplace will convert all items in the given list to TimestampedEntries before attempting the replace operation. The replace operation will delete the contents of the ExpirationCache \\`c\\`.\n\n```go\nfunc (c *ExpirationCache) Resync() error\n```\nResync will touch all objects to put them into the processing queue\n\n```go\nfunc (c *ExpirationCache) Update(obj interface{}) error\n```\nUpdate has not been implemented yet for lack of a use case, so this method simply calls \\`Add\\`. This effectively refreshes the timestamp.\n\n```go\ntype ExpirationPolicy interface {\n\tIsExpired(obj *timestampedEntry) bool\n}\n```\nExpirationPolicy dictates when an object expires. Currently only abstracted out so unittests don't rely on the system clock.\n\n```go\ntype ExplicitKey string\n```\nExplicitKey can be passed to MetaNamespaceKeyFunc if you have the key for the object but not the object itself.\n\n```go\ntype FIFO struct {\n\t// contains filtered or unexported fields\n}\n```\nFIFO receives adds and updates from a Reflector, and puts them in a queue for FIFO order processing. If multiple adds/updates of a single item happen while an item is in the queue before it has been processed, it will only be processed once, and when it is processed, the most recent version will be processed. This can't be done with a channel.\n\nFIFO solves this use case:\n\n  - You want to process every object (exactly) once.\n  - You want to process the most recent version of the object when you process it.\n  - You do not want to process deleted objects, they should be removed from the queue.\n  - You do not want to periodically reprocess objects.\n\nCompare with DeltaFIFO for other use cases.\n\n```go\nfunc NewFIFO(keyFunc KeyFunc) *FIFO\n```\nNewFIFO returns a Store which can be used to queue up items to process.\n\n```go\nfunc (f *FIFO) Add(obj interface{}) error\n```\nAdd inserts an item, and puts it in the queue. The item is only enqueued if it doesn't already exist in the set.\n\n```go\nfunc (f *FIFO) AddIfNotPresent(obj interface{}) error\n```\nAddIfNotPresent inserts an item, and puts it in the queue. If the item is already present in the set, it is neither enqueued nor added to the set.\n\nThis is useful in a single producer/consumer scenario so that the consumer can safely retry items without contending with the producer and potentially enqueueing stale items.\n\n```go\nfunc (f *FIFO) Close()\n```\nClose the queue.\n\n```go\nfunc (f *FIFO) Delete(obj interface{}) error\n```\nDelete removes an item. It doesn't add it to the queue, because this implementation assumes the consumer only cares about the objects, not the order in which they were created/added.\n\n```go\nfunc (f *FIFO) Get(obj interface{}) (item interface{}, exists bool, err error)\n```\nGet returns the requested item, or sets exists=false.\n\n```go\nfunc (f *FIFO) GetByKey(key string) (item interface{}, exists bool, err error)\n```\nGetByKey returns the requested item, or sets exists=false.\n\n```go\nfunc (f *FIFO) HasSynced() bool\n```\nReturn true if an Add/Update/Delete/AddIfNotPresent are called first, or an Update called first but the first batch of items inserted by Replace() has been popped\n\n```go\nfunc (f *FIFO) IsClosed() bool\n```\nChecks if the queue is closed\n\n```go\nfunc (f *FIFO) List() []interface{}\n```\nList returns a list of all the items.\n\n```go\nfunc (f *FIFO) ListKeys() []string\n```\nListKeys returns a list of all the keys of the objects currently in the FIFO.\n\n```go\nfunc (f *FIFO) Pop(process PopProcessFunc) (interface{}, error)\n```\nPop waits until an item is ready and processes it. If multiple items are ready, they are returned in the order in which they were added/updated. The item is removed from the queue (and the store) before it is processed, so if you don't successfully process it, it should be added back with AddIfNotPresent(). process function is called under lock, so it is safe update data structures in it that need to be in sync with the queue.\n\n```go\nfunc (f *FIFO) Replace(list []interface{}, resourceVersion string) error\n```\nReplace will delete the contents of 'f', using instead the given map. 'f' takes ownership of the map, you should not reference the map again after calling this function. f's queue is reset, too; upon return, it will contain the items in the map, in no particular order.\n\n```go\nfunc (f *FIFO) Resync() error\n```\nResync will touch all objects to put them into the processing queue\n\n```go\nfunc (f *FIFO) Update(obj interface{}) error\n```\nUpdate is the same as Add in this implementation.\n\n```go\ntype FakeCustomStore struct {\n\tAddFunc      func(obj interface{}) error\n\tUpdateFunc   func(obj interface{}) error\n\tDeleteFunc   func(obj interface{}) error\n\tListFunc     func() []interface{}\n\tListKeysFunc func() []string\n\tGetFunc      func(obj interface{}) (item interface{}, exists bool, err error)\n\tGetByKeyFunc func(key string) (item interface{}, exists bool, err error)\n\tReplaceFunc  func(list []interface{}, resourceVerion string) error\n\tResyncFunc   func() error\n}\n```\nFakeStore lets you define custom functions for store operations\n\n```go\nfunc (f *FakeCustomStore) Add(obj interface{}) error\n```\nAdd calls the custom Add function if defined\n\n```go\nfunc (f *FakeCustomStore) Delete(obj interface{}) error\n```\nDelete calls the custom Delete function if defined\n\n```go\nfunc (f *FakeCustomStore) Get(obj interface{}) (item interface{}, exists bool, err error)\n```\nGet calls the custom Get function if defined\n\n```go\nfunc (f *FakeCustomStore) GetByKey(key string) (item interface{}, exists bool, err error)\n```\nGetByKey calls the custom GetByKey function if defined\n\n```go\nfunc (f *FakeCustomStore) List() []interface{}\n```\nList calls the custom List function if defined\n\n```go\nfunc (f *FakeCustomStore) ListKeys() []string\n```\nListKeys calls the custom ListKeys function if defined\n\n```go\nfunc (f *FakeCustomStore) Replace(list []interface{}, resourceVersion string) error\n```\nReplace calls the custom Replace function if defined\n\n```go\nfunc (f *FakeCustomStore) Resync() error\n```\nResync calls the custom Resync function if defined\n\n```go\nfunc (f *FakeCustomStore) Update(obj interface{}) error\n```\nUpdate calls the custom Update function if defined\n\n```go\ntype FakeExpirationPolicy struct {\n\tNeverExpire     sets.String\n\tRetrieveKeyFunc KeyFunc\n}\n```\n\n```go\nfunc (p *FakeExpirationPolicy) IsExpired(obj *timestampedEntry) bool\n```\n\n```go\ntype FilteringResourceEventHandler struct {\n\tFilterFunc func(obj interface{}) bool\n\tHandler    ResourceEventHandler\n}\n```\nFilteringResourceEventHandler applies the provided filter to all events coming in, ensuring the appropriate nested handler method is invoked. An object that starts passing the filter after an update is considered an add, and an object that stops passing the filter after an update is considered a delete.\n\n```go\nfunc (r FilteringResourceEventHandler) OnAdd(obj interface{})\n```\nOnAdd calls the nested handler only if the filter succeeds\n\n```go\nfunc (r FilteringResourceEventHandler) OnDelete(obj interface{})\n```\nOnDelete calls the nested handler only if the filter succeeds\n\n```go\nfunc (r FilteringResourceEventHandler) OnUpdate(oldObj, newObj interface{})\n```\nOnUpdate ensures the proper handler is called depending on whether the filter matches\n\n```go\ntype GaugeMetric interface {\n\tSet(float64)\n}\n```\nGaugeMetric represents a single numerical value that can arbitrarily go up and down.\n\n```go\ntype GenericLister interface {\n\t// List will return all objects across namespaces\n\tList(selector labels.Selector) (ret []runtime.Object, err error)\n\t// Get will attempt to retrieve assuming that name==key\n\tGet(name string) (runtime.Object, error)\n\t// ByNamespace will give you a GenericNamespaceLister for one namespace\n\tByNamespace(namespace string) GenericNamespaceLister\n}\n```\nGenericLister is a lister skin on a generic Indexer\n\n```go\nfunc NewGenericLister(indexer Indexer, resource schema.GroupResource) GenericLister\n```\n\n```go\ntype GenericNamespaceLister interface {\n\t// List will return all objects in this namespace\n\tList(selector labels.Selector) (ret []runtime.Object, err error)\n\t// Get will attempt to retrieve by namespace and name\n\tGet(name string) (runtime.Object, error)\n}\n```\nGenericNamespaceLister is a lister skin on a generic Indexer\n\n```go\ntype Getter interface {\n\tGet() *restclient.Request\n}\n```\nGetter interface knows how to access Get method from RESTClient.\n\n```go\ntype Heap struct {\n\t// contains filtered or unexported fields\n}\n```\nHeap is a thread-safe producer/consumer queue that implements a heap data structure. It can be used to implement priority queues and similar data structures.\n\n```go\nfunc NewHeap(keyFn KeyFunc, lessFn LessFunc) *Heap\n```\nNewHeap returns a Heap which can be used to queue up items to process.\n\n```go\nfunc (h *Heap) Add(obj interface{}) error\n```\nAdd inserts an item, and puts it in the queue. The item is updated if it already exists.\n\n```go\nfunc (h *Heap) AddIfNotPresent(obj interface{}) error\n```\nAddIfNotPresent inserts an item, and puts it in the queue. If an item with the key is present in the map, no changes is made to the item.\n\nThis is useful in a single producer/consumer scenario so that the consumer can safely retry items without contending with the producer and potentially enqueueing stale items.\n\n```go\nfunc (h *Heap) BulkAdd(list []interface{}) error\n```\nAdds all the items in the list to the queue and then signals the condition variable. It is useful when the caller would like to add all of the items to the queue before consumer starts processing them.\n\n```go\nfunc (h *Heap) Close()\n```\nClose the Heap and signals condition variables that may be waiting to pop items from the heap.\n\n```go\nfunc (h *Heap) Delete(obj interface{}) error\n```\nDelete removes an item.\n\n```go\nfunc (h *Heap) Get(obj interface{}) (interface{}, bool, error)\n```\nGet returns the requested item, or sets exists=false.\n\n```go\nfunc (h *Heap) GetByKey(key string) (interface{}, bool, error)\n```\nGetByKey returns the requested item, or sets exists=false.\n\n```go\nfunc (h *Heap) IsClosed() bool\n```\nIsClosed returns true if the queue is closed.\n\n```go\nfunc (h *Heap) List() []interface{}\n```\nList returns a list of all the items.\n\n```go\nfunc (h *Heap) ListKeys() []string\n```\nListKeys returns a list of all the keys of the objects currently in the Heap.\n\n```go\nfunc (h *Heap) Pop() (interface{}, error)\n```\nPop waits until an item is ready. If multiple items are ready, they are returned in the order given by Heap.data.lessFunc.\n\n```go\nfunc (h *Heap) Update(obj interface{}) error\n```\nUpdate is the same as Add in this implementation. When the item does not exist, it is added.\n\n```go\ntype Index map[string]sets.String\n```\nIndex maps the indexed value to a set of keys in the store that match on that value\n\n```go\ntype IndexFunc func(obj interface{}) ([]string, error)\n```\nIndexFunc knows how to provide an indexed value for an object.\n\n```go\ntype Indexer interface {\n\tStore\n\t// Retrieve list of objects that match on the named indexing function\n\tIndex(indexName string, obj interface{}) ([]interface{}, error)\n\t// IndexKeys returns the set of keys that match on the named indexing function.\n\tIndexKeys(indexName, indexKey string) ([]string, error)\n\t// ListIndexFuncValues returns the list of generated values of an Index func\n\tListIndexFuncValues(indexName string) []string\n\t// ByIndex lists object that match on the named indexing function with the exact key\n\tByIndex(indexName, indexKey string) ([]interface{}, error)\n\t// GetIndexer return the indexers\n\tGetIndexers() Indexers\n\n\t// AddIndexers adds more indexers to this store.  If you call this after you already have data\n\t// in the store, the results are undefined.\n\tAddIndexers(newIndexers Indexers) error\n}\n```\nIndexer is a storage interface that lets you list objects using multiple indexing functions\n\n```go\nfunc NewIndexer(keyFunc KeyFunc, indexers Indexers) Indexer\n```\nNewIndexer returns an Indexer implemented simply with a map and a lock.\n\n```go\ntype Indexers map[string]IndexFunc\n```\nIndexers maps a name to a IndexFunc\n\n```go\ntype Indices map[string]Index\n```\nIndices maps a name to an Index\n\n```go\ntype InformerSynced func() bool\n```\nInformerSynced is a function that can be used to determine if an informer has synced.  This is useful for determining if caches have synced.\n\n```go\ntype KeyError struct {\n\tObj interface{}\n\tErr error\n}\n```\nKeyError will be returned any time a KeyFunc gives an error; it includes the object at fault.\n\n```go\nfunc (k KeyError) Error() string\n```\nError gives a human-readable description of the error.\n\n```go\ntype KeyFunc func(obj interface{}) (string, error)\n```\nKeyFunc knows how to make a key from an object. Implementations should be deterministic.\n\n```go\nfunc IndexFuncToKeyFuncAdapter(indexFunc IndexFunc) KeyFunc\n```\nIndexFuncToKeyFuncAdapter adapts an indexFunc to a keyFunc.  This is only useful if your index function returns unique values for every object.  This is conversion can create errors when more than one key is found.  You should prefer to make proper key and index functions.\n\n```go\ntype KeyGetter interface {\n\tGetByKey(key string) (interface{}, bool, error)\n}\n```\nA KeyGetter is anything that knows how to get the value stored under a given key.\n\n```go\ntype KeyLister interface {\n\tListKeys() []string\n}\n```\nA KeyLister is anything that knows how to list its keys.\n\n```go\ntype KeyListerGetter interface {\n\tKeyLister\n\tKeyGetter\n}\n```\nA KeyListerGetter is anything that knows how to list its keys and look up by key.\n\n```go\ntype LessFunc func(interface{}, interface{}) bool\n```\n\n```go\ntype ListFunc func(options metav1.ListOptions) (runtime.Object, error)\n```\nListFunc knows how to list resources\n\n```go\ntype ListWatch struct {\n\tListFunc  ListFunc\n\tWatchFunc WatchFunc\n\t// DisableChunking requests no chunking for this list watcher.\n\tDisableChunking bool\n}\n```\nListWatch knows how to list and watch a set of apiserver resources.  It satisfies the ListerWatcher interface. It is a convenience function for users of NewReflector, etc. ListFunc and WatchFunc must not be nil\n\n```go\nfunc NewFilteredListWatchFromClient(c Getter, resource string, namespace string, optionsModifier func(options *metav1.ListOptions)) *ListWatch\n```\nNewFilteredListWatchFromClient creates a new ListWatch from the specified client, resource, namespace, and option modifier. Option modifier is a function takes a ListOptions and modifies the consumed ListOptions. Provide customized modifier function to apply modification to ListOptions with a field selector, a label selector, or any other desired options.\n\n```go\nfunc NewListWatchFromClient(c Getter, resource string, namespace string, fieldSelector fields.Selector) *ListWatch\n```\nNewListWatchFromClient creates a new ListWatch from the specified client, resource, namespace and field selector.\n\n```go\nfunc (lw *ListWatch) List(options metav1.ListOptions) (runtime.Object, error)\n```\nList a set of apiserver resources\n\n```go\nfunc (lw *ListWatch) Watch(options metav1.ListOptions) (watch.Interface, error)\n```\nWatch a set of apiserver resources\n\n```go\ntype Lister interface {\n\t// List should return a list type object; the Items field will be extracted, and the\n\t// ResourceVersion field will be used to start the watch in the right place.\n\tList(options metav1.ListOptions) (runtime.Object, error)\n}\n```\nLister is any object that knows how to perform an initial list.\n\n```go\ntype ListerWatcher interface {\n\tLister\n\tWatcher\n}\n```\nListerWatcher is any object that knows how to perform an initial list and start a watch on a resource.\n\n```go\ntype MetricsProvider interface {\n\tNewListsMetric(name string) CounterMetric\n\tNewListDurationMetric(name string) SummaryMetric\n\tNewItemsInListMetric(name string) SummaryMetric\n\n\tNewWatchesMetric(name string) CounterMetric\n\tNewShortWatchesMetric(name string) CounterMetric\n\tNewWatchDurationMetric(name string) SummaryMetric\n\tNewItemsInWatchMetric(name string) SummaryMetric\n\n\tNewLastResourceVersionMetric(name string) GaugeMetric\n}\n```\nMetricsProvider generates various metrics used by the reflector.\n\n```go\ntype MutationCache interface {\n\tGetByKey(key string) (interface{}, bool, error)\n\tByIndex(indexName, indexKey string) ([]interface{}, error)\n\tMutation(interface{})\n}\n```\nMutationCache 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. TODO find a way to layer this into an informer/lister\n\n```go\nfunc NewIntegerResourceVersionMutationCache(backingCache Store, indexer Indexer, ttl time.Duration, includeAdds bool) MutationCache\n```\nNewIntegerResourceVersionMutationCache returns a MutationCache that understands how to deal with objects that have a resource version that:\n\n  - is an integer\n  - increases when updated\n  - is comparable across the same resource in a namespace\n\nMost backends will have these semantics. Indexer may be nil. ttl controls how long an item remains in the mutation cache before it is removed.\n\nIf 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.\n\n```go\ntype PopProcessFunc func(interface{}) error\n```\nPopProcessFunc is passed to Pop() method of Queue interface. It is supposed to process the element popped from the queue.\n\n```go\ntype ProcessFunc func(obj interface{}) error\n```\nProcessFunc processes a single object.\n\n```go\ntype Queue interface {\n\tStore\n\n\t// Pop blocks until it has something to process.\n\t// It returns the object that was process and the result of processing.\n\t// The PopProcessFunc may return an ErrRequeue{...} to indicate the item\n\t// should be requeued before releasing the lock on the queue.\n\tPop(PopProcessFunc) (interface{}, error)\n\n\t// AddIfNotPresent adds a value previously\n\t// returned by Pop back into the queue as long\n\t// as nothing else (presumably more recent)\n\t// has since been added.\n\tAddIfNotPresent(interface{}) error\n\n\t// HasSynced returns true if the first batch of items has been popped\n\tHasSynced() bool\n\n\t// Close queue\n\tClose()\n}\n```\nQueue is exactly like a Store, but has a Pop() method too.\n\n```go\ntype Reflector struct {\n\tShouldResync func() bool\n\t// contains filtered or unexported fields\n}\n```\nReflector watches a specified resource and causes all changes to be reflected in the given store.\n\n```go\nfunc NewNamedReflector(name string, lw ListerWatcher, expectedType interface{}, store Store, resyncPeriod time.Duration) *Reflector\n```\nNewNamedReflector same as NewReflector, but with a specified name for logging\n\n```go\nfunc NewReflector(lw ListerWatcher, expectedType interface{}, store Store, resyncPeriod time.Duration) *Reflector\n```\nNewReflector creates a new Reflector object which will keep the given store up to date with the server's contents for the given resource. Reflector promises to only put things in the store that have the type of expectedType, unless expectedType is nil. If resyncPeriod is non-zero, then lists will be executed after every resyncPeriod, so that you can use reflectors to periodically process everything as well as incrementally processing the things that change.\n\n```go\nfunc (r *Reflector) LastSyncResourceVersion() string\n```\nLastSyncResourceVersion is the resource version observed when last sync with the underlying store The value returned is not synchronized with access to the underlying store and is not thread-safe\n\n```go\nfunc (r *Reflector) ListAndWatch(stopCh \u003c-chan struct{}) error\n```\nListAndWatch first lists all items and get the resource version at the moment of call, and then use the resource version to watch. It returns error if ListAndWatch didn't even try to initialize watch.\n\n```go\nfunc (r *Reflector) Run(stopCh \u003c-chan struct{})\n```\nRun starts a watch and handles watch events. Will restart the watch if it is closed. Run will exit when stopCh is closed.\n\n```go\ntype ResourceEventHandler interface {\n\tOnAdd(obj interface{})\n\tOnUpdate(oldObj, newObj interface{})\n\tOnDelete(obj interface{})\n}\n```\nResourceEventHandler can handle notifications for events that happen to a resource. The events are informational only, so you can't return an error.\n\n  - OnAdd is called when an object is added.\n  - OnUpdate is called when an object is modified. Note that oldObj is the last known state of the object-- it is possible that several changes were combined together, so you can't use this to see every single change. OnUpdate is also called when a re-list happens, and it will get called even if nothing changed. This is useful for periodically evaluating or syncing something.\n  - OnDelete will get the final state of the item if it is known, otherwise it will get an object of type DeletedFinalStateUnknown. This can happen if the watch is closed and misses the delete event and we don't notice the deletion until the subsequent re-list.\n\n```go\ntype ResourceEventHandlerFuncs struct {\n\tAddFunc    func(obj interface{})\n\tUpdateFunc func(oldObj, newObj interface{})\n\tDeleteFunc func(obj interface{})\n}\n```\nResourceEventHandlerFuncs is an adaptor to let you easily specify as many or as few of the notification functions as you want while still implementing ResourceEventHandler.\n\n```go\nfunc (r ResourceEventHandlerFuncs) OnAdd(obj interface{})\n```\nOnAdd calls AddFunc if it's not nil.\n\n```go\nfunc (r ResourceEventHandlerFuncs) OnDelete(obj interface{})\n```\nOnDelete calls DeleteFunc if it's not nil.\n\n```go\nfunc (r ResourceEventHandlerFuncs) OnUpdate(oldObj, newObj interface{})\n```\nOnUpdate calls UpdateFunc if it's not nil.\n\n```go\ntype ResourceVersionComparator interface {\n\tCompareResourceVersion(lhs, rhs runtime.Object) int\n}\n```\n\n```go\ntype SharedIndexInformer interface {\n\tSharedInformer\n\t// AddIndexers add indexers to the informer before it starts.\n\tAddIndexers(indexers Indexers) error\n\tGetIndexer() Indexer\n}\n```\n\n```go\nfunc NewSharedIndexInformer(lw ListerWatcher, objType runtime.Object, defaultEventHandlerResyncPeriod time.Duration, indexers Indexers) SharedIndexInformer\n```\nNewSharedIndexInformer creates a new instance for the listwatcher.\n\n```go\ntype SharedInformer interface {\n\t// AddEventHandler adds an event handler to the shared informer using the shared informer's resync\n\t// period.  Events to a single handler are delivered sequentially, but there is no coordination\n\t// between different handlers.\n\tAddEventHandler(handler ResourceEventHandler)\n\t// AddEventHandlerWithResyncPeriod adds an event handler to the shared informer using the\n\t// specified resync period.  Events to a single handler are delivered sequentially, but there is\n\t// no coordination between different handlers.\n\tAddEventHandlerWithResyncPeriod(handler ResourceEventHandler, resyncPeriod time.Duration)\n\t// GetStore returns the Store.\n\tGetStore() Store\n\t// GetController gives back a synthetic interface that \"votes\" to start the informer\n\tGetController() Controller\n\t// Run starts the shared informer, which will be stopped when stopCh is closed.\n\tRun(stopCh \u003c-chan struct{})\n\t// HasSynced returns true if the shared informer's store has synced.\n\tHasSynced() bool\n\t// LastSyncResourceVersion is the resource version observed when last synced with the underlying\n\t// store. The value returned is not synchronized with access to the underlying store and is not\n\t// thread-safe.\n\tLastSyncResourceVersion() string\n}\n```\nSharedInformer has a shared data cache and is capable of distributing notifications for changes to the cache to multiple listeners who registered via AddEventHandler. If you use this, there is one behavior change compared to a standard Informer.  When you receive a notification, the cache will be AT LEAST as fresh as the notification, but it MAY be more fresh.  You should NOT depend on the contents of the cache exactly matching the notification you've received in handler functions.  If there was a create, followed by a delete, the cache may NOT have your item.  This has advantages over the broadcaster since it allows us to share a common cache across many controllers. Extending the broadcaster would have required us keep duplicate caches for each watch.\n\n```go\nfunc NewSharedInformer(lw ListerWatcher, objType runtime.Object, resyncPeriod time.Duration) SharedInformer\n```\nNewSharedInformer creates a new instance for the listwatcher.\n\n```go\ntype ShouldResyncFunc func() bool\n```\nShouldResyncFunc is a type of function that indicates if a reflector should perform a resync or not. It can be used by a shared informer to support multiple event handlers with custom resync periods.\n\n```go\ntype Store interface {\n\tAdd(obj interface{}) error\n\tUpdate(obj interface{}) error\n\tDelete(obj interface{}) error\n\tList() []interface{}\n\tListKeys() []string\n\tGet(obj interface{}) (item interface{}, exists bool, err error)\n\tGetByKey(key string) (item interface{}, exists bool, err error)\n\n\t// Replace will delete the contents of the store, using instead the\n\t// given list. Store takes ownership of the list, you should not reference\n\t// it after calling this function.\n\tReplace([]interface{}, string) error\n\tResync() error\n}\n```\nStore is a generic object storage interface. Reflector knows how to watch a server and update a store. A generic store is provided, which allows Reflector to be used as a local caching system, and an LRU store, which allows Reflector to work like a queue of items yet to be processed.\n\nStore makes no assumptions about stored object identity; it is the responsibility of a Store implementation to provide a mechanism to correctly key objects and to define the contract for obtaining objects by some arbitrary key type.\n\n```go\nfunc NewFakeExpirationStore(keyFunc KeyFunc, deletedKeys chan\u003c- string, expirationPolicy ExpirationPolicy, cacheClock clock.Clock) Store\n```\n\n```go\nfunc NewStore(keyFunc KeyFunc) Store\n```\nNewStore returns a Store implemented simply with a map and a lock.\n\n```go\nfunc NewTTLStore(keyFunc KeyFunc, ttl time.Duration) Store\n```\nNewTTLStore creates and returns a ExpirationCache with a TTLPolicy\n\n```go\ntype SummaryMetric interface {\n\tObserve(float64)\n}\n```\nSummaryMetric captures individual observations.\n\n```go\ntype TTLPolicy struct {\n\t//\t \u003e0: Expire entries with an age \u003e ttl\n\t//\t\u003c=0: Don't expire any entry\n\tTtl time.Duration\n\n\t// Clock used to calculate ttl expiration\n\tClock clock.Clock\n}\n```\nTTLPolicy implements a ttl based ExpirationPolicy.\n\n```go\nfunc (p *TTLPolicy) IsExpired(obj *timestampedEntry) bool\n```\nIsExpired returns true if the given object is older than the ttl, or it can't determine its age.\n\n```go\ntype ThreadSafeStore interface {\n\tAdd(key string, obj interface{})\n\tUpdate(key string, obj interface{})\n\tDelete(key string)\n\tGet(key string) (item interface{}, exists bool)\n\tList() []interface{}\n\tListKeys() []string\n\tReplace(map[string]interface{}, string)\n\tIndex(indexName string, obj interface{}) ([]interface{}, error)\n\tIndexKeys(indexName, indexKey string) ([]string, error)\n\tListIndexFuncValues(name string) []string\n\tByIndex(indexName, indexKey string) ([]interface{}, error)\n\tGetIndexers() Indexers\n\n\t// AddIndexers adds more indexers to this store.  If you call this after you already have data\n\t// in the store, the results are undefined.\n\tAddIndexers(newIndexers Indexers) error\n\tResync() error\n}\n```\nThreadSafeStore is an interface that allows concurrent access to a storage backend. TL;DR caveats: you must not modify anything returned by Get or List as it will break the indexing feature in addition to not being thread safe.\n\nThe guarantees of thread safety provided by List/Get are only valid if the caller treats returned items as read-only. For example, a pointer inserted in the store through \\`Add\\` will be returned as is by \\`Get\\`. Multiple clients might invoke \\`Get\\` on the same key and modify the pointer in a non-thread-safe way. Also note that modifying objects stored by the indexers (if any) will \\*not\\* automatically lead to a re-index. So it's not a good idea to directly modify the objects returned by Get/List, in general.\n\n```go\nfunc NewThreadSafeStore(indexers Indexers, indices Indices) ThreadSafeStore\n```\n\n```go\ntype UndeltaStore struct {\n\tStore\n\tPushFunc func([]interface{})\n}\n```\nUndeltaStore listens to incremental updates and sends complete state on every change. It implements the Store interface so that it can receive a stream of mirrored objects from Reflector.  Whenever it receives any complete (Store.Replace) or incremental change (Store.Add, Store.Update, Store.Delete), it sends the complete state by calling PushFunc. It is thread-safe.  It guarantees that every change (Add, Update, Replace, Delete) results in one call to PushFunc, but sometimes PushFunc may be called twice with the same values. PushFunc should be thread safe.\n\n```go\nfunc NewUndeltaStore(pushFunc func([]interface{}), keyFunc KeyFunc) *UndeltaStore\n```\nNewUndeltaStore returns an UndeltaStore implemented with a Store.\n\n```go\nfunc (u *UndeltaStore) Add(obj interface{}) error\n```\n\n```go\nfunc (u *UndeltaStore) Delete(obj interface{}) error\n```\n\n```go\nfunc (u *UndeltaStore) Replace(list []interface{}, resourceVersion string) error\n```\n\n```go\nfunc (u *UndeltaStore) Update(obj interface{}) error\n```\n\n```go\ntype WatchFunc func(options metav1.ListOptions) (watch.Interface, error)\n```\nWatchFunc knows how to watch resources\n\n```go\ntype Watcher interface {\n\t// Watch should begin a watch at the specified version.\n\tWatch(options metav1.ListOptions) (watch.Interface, error)\n}\n```\nWatcher is any object that knows how to start a watch on a resource.\n\n","path":"github.com/unitytech/client-go/tools/cache","name":"cache","synopsis":"Package cache is a client-side caching mechanism.","isRedistributable":true}
