Class Cache<ApiType extends io.kubernetes.client.common.KubernetesObject>

java.lang.Object
io.kubernetes.client.informer.cache.Cache<ApiType>
All Implemented Interfaces:
Indexer<ApiType>, Store<ApiType>

public class Cache<ApiType extends io.kubernetes.client.common.KubernetesObject> extends Object implements Indexer<ApiType>
Cache is a java port of k/client-go's ThreadSafeStore. It basically saves and indexes all the entries.
  • Constructor Details

    • Cache

      public Cache()
    • Cache

      public Cache(String indexName, Function<ApiType,List<String>> indexFunc, Function<ApiType,String> keyFunc)
      Constructor.
      Parameters:
      indexName - the index name, an unique name representing the index
      indexFunc - the index func by which we map multiple object to an index for querying
      keyFunc - the key func by which we map one object to an unique key for storing
  • Method Details

    • add

      public void add(ApiType obj)
      Add objects.
      Specified by:
      add in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      obj - the obj
    • update

      public void update(ApiType obj)
      Update the object.
      Specified by:
      update in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      obj - the obj
    • delete

      public void delete(ApiType obj)
      Delete the object.
      Specified by:
      delete in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      obj - the obj
    • replace

      public void replace(List<ApiType> list, String resourceVersion)
      Replace the content in the cache completely.
      Specified by:
      replace in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      list - the list
      resourceVersion - the resource version
    • resync

      public void resync()
      Resync.
      Specified by:
      resync in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
    • listKeys

      public List<String> listKeys()
      List keys.
      Specified by:
      listKeys in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Returns:
      the list
    • get

      public ApiType get(ApiType obj)
      Get object t.
      Specified by:
      get in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      obj - the obj
      Returns:
      the t
    • list

      public List<ApiType> list()
      List all objects in the cache.
      Specified by:
      list in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Returns:
      the list
    • getByKey

      public ApiType getByKey(String key)
      Gets get by key.
      Specified by:
      getByKey in interface Store<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      key - the key
      Returns:
      the get by key
    • index

      public List<ApiType> index(String indexName, ApiType obj)
      Get objects .
      Specified by:
      index in interface Indexer<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      indexName - the index name
      obj - the obj
      Returns:
      the list
    • indexKeys

      public List<String> indexKeys(String indexName, String indexKey)
      Index keys list.
      Specified by:
      indexKeys in interface Indexer<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      indexName - the index name
      indexKey - the index key
      Returns:
      the list
    • byIndex

      public List<ApiType> byIndex(String indexName, String indexKey)
      By index list.
      Specified by:
      byIndex in interface Indexer<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      indexName - the index name
      indexKey - the index key
      Returns:
      the list
    • getIndexers

      public Map<String,Function<ApiType,List<String>>> getIndexers()
      Return the indexers registered with the cache.
      Specified by:
      getIndexers in interface Indexer<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Returns:
      registered indexers
    • addIndexers

      public void addIndexers(Map<String,Function<ApiType,List<String>>> newIndexers)
      Add additional indexers to the cache.
      Specified by:
      addIndexers in interface Indexer<ApiType extends io.kubernetes.client.common.KubernetesObject>
      Parameters:
      newIndexers - indexers to add
    • updateIndices

      public void updateIndices(ApiType oldObj, ApiType newObj, String key)
      updateIndices modifies the objects location in the managed indexes, if this is an update, you must provide an oldObj.

      Note: updateIndices must be called from a function that already has a lock on the cache.

      Parameters:
      oldObj - the old obj
      newObj - the new obj
      key - the key
    • addIndexFunc

      public void addIndexFunc(String indexName, Function<ApiType,List<String>> indexFunc)
      Add index func.
      Parameters:
      indexName - the index name
      indexFunc - the index func
    • getKeyFunc

      public Function<ApiType,String> getKeyFunc()
    • setKeyFunc

      public void setKeyFunc(Function<ApiType,String> keyFunc)