.NET Client Documentation
5.1.1
Search Results for

    Show / Hide Table of Contents

    PutIfAbsentAsync Method

    PutIfAbsentAsync(TKey, TValue)

    Adds an entry if no entry with the key already exists. Returns the new value, or the existing value if the entry already exists.

    Declaration
    Task<TValue> PutIfAbsentAsync(TKey key, TValue value)
    Parameters
    TKey key

    A key.

    TValue value

    The value.

    Returns
    Task<TValue>

    The value for the key. This will be either the existing value for the key if the entry already exists, or the new value if the no entry with the key already existed.

    Remarks

    The value never expires.

    The value becomes idle after the server-configured idle time.

    This methods interacts with the server-side MapStore. If no value for the specified key is found in memory, MapLoader.load(...) is invoked to try to load the value from the MapStore backing the map, if any. If write-through persistence is configured, before the value is stored in memory, MapStore.store is invoked to write the value to the store.

    PutIfAbsentAsync(TKey, TValue, TimeSpan)

    Adds an entry with a time-to-live if no entry with the key already exists. Returns the new value, or the existing value if the entry already exists.

    Declaration
    Task<TValue> PutIfAbsentAsync(TKey key, TValue value, TimeSpan timeToLive)
    Parameters
    TKey key

    A key.

    TValue value

    A value.

    TimeSpan timeToLive

    A time to live (0ms to live forever; -1ms to use the server-configured value).

    Returns
    Task<TValue>

    The value for the key. This will be either the existing value for the key if the entry already exists, or the new value if the no entry with the key already existed.

    Remarks

    The value is automatically expired, evicted and removed after the timeToLive has elapsed. If timeToLive is 0ms, the value is retained indefinitely. If it is -1ms, it lives for the duration of the server-configured time-to-live.

    The value becomes idle after the server-configured idle time.

    This methods interacts with the server-side MapStore. If no value for the specified key is found in memory, MapLoader.load(...) is invoked to try to load the value from the MapStore backing the map, if any. If write-through persistence is configured, before the value is stored in memory, MapStore.store is invoked to write the value to the store.

    PutIfAbsentAsync(TKey, TValue, TimeSpan, TimeSpan)

    Adds an entry with a time-to-live and a max-idle if no entry with the key already exists. Returns the new value, or the existing value if the entry already exists.

    Declaration
    Task<TValue> PutIfAbsentAsync(TKey key, TValue value, TimeSpan timeToLive, TimeSpan maxIdle)
    Parameters
    TKey key

    A key.

    TValue value

    A value.

    TimeSpan timeToLive

    A time to live (0ms to live forever; -1ms to use the server-configured value).

    TimeSpan maxIdle

    A max-idle time (0ms to never become idle).

    Returns
    Task<TValue>

    The value for the key. This will be either the existing value for the key if the entry already exists, or the new value if the no entry with the key already existed.

    Remarks

    The value is automatically expired, evicted and removed after the timeToLive has elapsed. If timeToLive is 0ms, the value is retained indefinitely. If it is -1ms, it lives for the duration of the server-configured time-to-live.

    The value is considered idle after the maxIdle has elapsed. If it is 0ms, the value never becomes idle.

    This methods interacts with the server-side MapStore. If no value for the specified key is found in memory, MapLoader.load(...) is invoked to try to load the value from the MapStore backing the map, if any. If write-through persistence is configured, before the value is stored in memory, MapStore.store is invoked to write the value to the store.

    In This Article
    Back to top Copyright © 2010-2022 Hazelcast, Inc. All rights reserved.
    Generated by DocFX.