org.apache.ignite.client

## Interface ClientCache<K,V>

-     public interface ClientCache<K,V>

  Thin client cache.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Clears the contents of the cache.
    `boolean` | `containsKey(K key)` Determines if the `ClientCache` contains an entry for the specified key.
    `V` | `get(K key)` Gets an entry from the cache.
    `Map<K,V>` | `getAll(Set<? extends K> keys)` Gets a collection of entries from the `ClientCache`, returning them as `Map` of the values associated with the set of keys requested.
    `V` | `getAndPut(K key, V val)` Associates the specified value with the specified key in this cache, returning an existing value if one existed.
    `V` | `getAndRemove(K key)` Atomically removes the entry for a key only if currently mapped to some value.
    `V` | `getAndReplace(K key, V val)` Atomically replaces the value for a given key if and only if there is a value currently mapped by the key.
    `ClientCacheConfiguration` | `getConfiguration()`
    `String` | `getName()`
    `void` | `put(K key, V val)` Associates the specified value with the specified key in the cache.
    `void` | `putAll(Map<? extends K,? extends V> map)` Copies all of the entries from the specified map to the `ClientCache`.
    `boolean` | `putIfAbsent(K key, V val)` Atomically associates the specified key with the given value if it is not already associated with a value.
    `<R> QueryCursor<R>` | `query(Query<R> qry)` Queries cache.
    `FieldsQueryCursor<List<?>>` | `query(SqlFieldsQuery qry)` Convenience method to execute `SqlFieldsQuery`.
    `boolean` | `remove(K key)` Removes the mapping for a key from this cache if it is present.
    `boolean` | `remove(K key, V oldVal)` Atomically removes the mapping for a key only if currently mapped to the given value.
    `void` | `removeAll()` Removes all of the mappings from this cache.
    `void` | `removeAll(Set<? extends K> keys)` Removes entries for the specified keys.
    `boolean` | `replace(K key, V val)` Atomically replaces the entry for a key only if currently mapped to some value.
    `boolean` | `replace(K key, V oldVal, V newVal)` Atomically replaces the entry for a key only if currently mapped to a given value.
    `int` | `size(CachePeekMode... peekModes)` Gets the number of all entries cached across all nodes.
    `<K1,V1> ClientCache<K1,V1>` | `withExpirePolicy(javax.cache.expiry.ExpiryPolicy expirePlc)` Returns cache with the specified expired policy set.
    `<K1,V1> ClientCache<K1,V1>` | `withKeepBinary()` Returns cache that will operate with binary objects.

- - ### Method Detail

    - #### get

          V get(K key)
          throws ClientException

      Gets an entry from the cache.
      Parameters:
        `key` - the key whose associated value is to be returned
      Returns:
        the element, or null, if it does not exist.
      Throws:
        `NullPointerException` - if the key is null.
        `ClientException`

    - #### put

          void put(K key,
                   V val)
            throws ClientException

      Associates the specified value with the specified key in the cache.

      If the `ClientCache` previously contained a mapping for the key, the old value is replaced by the specified value.

      Parameters:
        `key` - key with which the specified value is to be associated
        `val` - value to be associated with the specified key.
      Throws:
        `NullPointerException` - if key is null or if value is null.
        `ClientException`

    - #### containsKey

          boolean containsKey(K key)
                       throws ClientException

      Determines if the `ClientCache` contains an entry for the specified key.

      More formally, returns `true` if and only if this cache contains a mapping for a key `k` such that `key.equals(k)`. (There can be at most one such mapping)

      Parameters:
        `key` - key whose presence in this cache is to be tested.
      Returns:
        `true` if this map contains a mapping for the specified key.
      Throws:
        `ClientException`

    - #### getName

          String getName()

      Returns:
        The name of the cache.

    - #### getConfiguration

          ClientCacheConfiguration getConfiguration()
                                             throws ClientException

      Returns:
        The cache configuration.
      Throws:
        `ClientException`

    - #### size

          int size(CachePeekMode... peekModes)
            throws ClientException

      Gets the number of all entries cached across all nodes. By default, if `peekModes` value isn't provided, only size of primary copies across all nodes will be returned. This behavior is identical to calling this method with `CachePeekMode.PRIMARY` peek mode.

      NOTE: this operation is distributed and will query all participating nodes for their cache sizes.

      Parameters:
        `peekModes` - Optional peek modes. If not provided, then total cache size is returned.
      Throws:
        `ClientException`

    - #### getAll

          Map<K,V> getAll(Set<? extends K> keys)
                   throws ClientException

      Gets a collection of entries from the `ClientCache`, returning them as `Map` of the values associated with the set of keys requested.
      Parameters:
        `keys` - The keys whose associated values are to be returned.
      Returns:
        A map of entries that were found for the given keys. Keys not found in the cache are not in the returned map.
      Throws:
        `ClientException`

    - #### putAll

          void putAll(Map<? extends K,? extends V> map)
               throws ClientException

      Copies all of the entries from the specified map to the `ClientCache`.

      The effect of this call is equivalent to that of calling `put(k, v)` on this cache once for each mapping from key `k` to value `v` in the specified map.

      The order in which the individual puts occur is undefined.

      The behavior of this operation is undefined if entries in the cache corresponding to entries in the map are modified or removed while this operation is in progress. or if map is modified while the operation is in progress.

      Parameters:
        `map` - Mappings to be stored in this cache.
      Throws:
        `ClientException`

    - #### replace

          boolean replace(K key,
                          V oldVal,
                          V newVal)
                   throws ClientException

      Atomically replaces the entry for a key only if currently mapped to a given value.

      This is equivalent to:

           if (cache.containsKey(key) && equals(cache.get(key), oldValue)) {
            cache.put(key, newValue);
           return true;
           } else {
            return false;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - Key with which the specified value is associated.
        `oldVal` - Value expected to be associated with the specified key.
        `newVal` - Value to be associated with the specified key.
      Returns:
        `true` if the value was replaced
      Throws:
        `ClientException`

    - #### replace

          boolean replace(K key,
                          V val)
                   throws ClientException

      Atomically replaces the entry for a key only if currently mapped to some value.

      This is equivalent to

           if (cache.containsKey(key)) {
             cache.put(key, value);
             return true;
           } else {
             return false;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - The key with which the specified value is associated.
        `val` - The value to be associated with the specified key.
      Returns:
        `true` if the value was replaced.
      Throws:
        `ClientException`

    - #### remove

          boolean remove(K key)
                  throws ClientException

      Removes the mapping for a key from this cache if it is present.

      More formally, if this cache contains a mapping from key `k` to value `v` such that `(key==null ? k==null : key.equals(k))`, that mapping is removed. (The cache can contain at most one such mapping.)

      Returns `true` if this cache previously associated the key, or `false` if the cache contained no mapping for the key.

      The cache will not contain a mapping for the specified key once the call returns.

      Parameters:
        `key` - Key whose mapping is to be removed from the cache.
      Returns:
        `false` if there was no matching key.
      Throws:
        `ClientException`

    - #### remove

          boolean remove(K key,
                         V oldVal)
                  throws ClientException

      Atomically removes the mapping for a key only if currently mapped to the given value.

      This is equivalent to:

           if (cache.containsKey(key) && equals(cache.get(key), oldValue) {
             cache.remove(key);
             return true;
           } else {
             return false;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - Key whose mapping is to be removed from the cache.
        `oldVal` - Value expected to be associated with the specified key.
      Returns:
        `false` if there was no matching key.
      Throws:
        `ClientException`

    - #### removeAll

          void removeAll(Set<? extends K> keys)
                  throws ClientException

      Removes entries for the specified keys.

      The order in which the individual entries are removed is undefined.

      Parameters:
        `keys` - The keys to remove.
      Throws:
        `ClientException`

    - #### removeAll

          void removeAll()
                  throws ClientException

      Removes all of the mappings from this cache.

      The order that the individual entries are removed is undefined.

      Throws:
        `ClientException`

    - #### getAndPut

          V getAndPut(K key,
                      V val)
               throws ClientException

      Associates the specified value with the specified key in this cache, returning an existing value if one existed.

      If the cache previously contained a mapping for the key, the old value is replaced by the specified value. (A cache `c` is said to contain a mapping for a key `k` if and only if `c.containsKey(k)` would return `true`.)

      The previous value is returned, or null if there was no value associated with the key previously.

      Parameters:
        `key` - Key with which the specified value is to be associated.
        `val` - Value to be associated with the specified key.
      Returns:
        The value associated with the key at the start of the operation or null if none was associated.
      Throws:
        `ClientException`

    - #### getAndRemove

          V getAndRemove(K key)
                  throws ClientException

      Atomically removes the entry for a key only if currently mapped to some value.

      This is equivalent to:

           if (cache.containsKey(key)) {
             V oldValue = cache.get(key);
             cache.remove(key);
             return oldValue;
           } else {
             return null;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - Key with which the specified value is associated.
      Returns:
        The value if one existed or null if no mapping existed for this key.
      Throws:
        `ClientException`

    - #### getAndReplace

          V getAndReplace(K key,
                          V val)
                   throws ClientException

      Atomically replaces the value for a given key if and only if there is a value currently mapped by the key.

      This is equivalent to

           if (cache.containsKey(key)) {
             V oldValue = cache.get(key);
             cache.put(key, value);
             return oldValue;
           } else {
             return null;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - Key with which the specified value is associated.
        `val` - Value to be associated with the specified key.
      Returns:
        The previous value associated with the specified key, or `null` if there was no mapping for the key.
      Throws:
        `ClientException`

    - #### putIfAbsent

          boolean putIfAbsent(K key,
                              V val)
                       throws ClientException

      Atomically associates the specified key with the given value if it is not already associated with a value.

      This is equivalent to:

           if (!cache.containsKey(key)) {}
             cache.put(key, value);
             return true;
           } else {
             return false;
           }

      except that the action is performed atomically.
      Parameters:
        `key` - Key with which the specified value is to be associated.
        `val` - Value to be associated with the specified key.
      Returns:
        `true` if a value was set.
      Throws:
        `ClientException`

    - #### clear

          void clear()
              throws ClientException

      Clears the contents of the cache.
      Throws:
        `ClientException`

    - #### withKeepBinary

          <K1,V1> ClientCache<K1,V1> withKeepBinary()

      Returns cache that will operate with binary objects.

      Cache returned by this method will not be forced to deserialize binary objects, so keys and values will be returned from cache API methods without changes. Therefore, signature of the cache can contain only following types:

      - `org.apache.ignite.binary.BinaryObject` for binary classes
      - All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)
      - Arrays of primitives (byte[], int[], ...)
      - `String` and array of `String`s
      - `UUID` and array of `UUID`s
      - `Date` and array of `Date`s
      - `Timestamp` and array of `Timestamp`s
      - Enums and array of enums
      - Maps, collections and array of objects (but objects inside them will still be converted if they are binary)

      For example, if you use `Integer` as a key and `Value` class as a value (which will be stored in binary format), you should acquire following projection to avoid deserialization:

           CacheClient prj = cache.withKeepBinary();

           // Value is not deserialized and returned in binary format.
           BinaryObject po = prj.get(1);

      Note that this method makes sense only if cache is working in binary mode if default marshaller is used. If not, this method is no-op and will return current cache.

      Returns:
        New cache instance for binary objects.

    - #### withExpirePolicy

          <K1,V1> ClientCache<K1,V1> withExpirePolicy(javax.cache.expiry.ExpiryPolicy expirePlc)

      Returns cache with the specified expired policy set. This policy will be used for each operation invoked on the returned cache.
      Returns:
        Cache instance with the specified expiry policy set.

    - #### query

          <R> QueryCursor<R> query(Query<R> qry)

      Queries cache. Supports `ScanQuery` and `SqlFieldsQuery`.
      Parameters:
        `qry` - Query.
      Returns:
        Cursor.

    - #### query

          FieldsQueryCursor<List<?>> query(SqlFieldsQuery qry)

      Convenience method to execute `SqlFieldsQuery`.
      Parameters:
        `qry` - Query.
      Returns:
        Cursor.

2020 Copyright © Apache Software Foundation
| Follow @ApacheIgnite
Ignite Database and Caching Platform | : ver. 2.9.1
Release Date | : December 9 2020