Function insert

Summary

#include <lib/inc/drogon/CacheMap.h>

(1) void insert(const T1 &key, T2 &&value, size_t timeout=0, std::function< void()> timeoutCallback=std::function< void()>())

(2) void insert(const T1 &key, const T2 &value, size_t timeout=0, std::function< void()> timeoutCallback=std::function< void()>())

Function overload

Synopsis

#include <lib/inc/drogon/CacheMap.h>

void insert(const T1 &key, T2 &&value, size_t timeout=0, std::function< void()> timeoutCallback=std::function< void()>())

Description

Insert a key-value pair into the cache.

Parameters:

key - The key

value - The value

timeout - The timeout in seconds, if timeout > 0, the value will be erased within the 'timeout' seconds after the last access. If the timeout is zero, the value exists until being removed explicitly.

timeoutCallback - is called when the timeout expires.

Source

Lines 161-186 in lib/inc/drogon/CacheMap.h.

void insert(const T1 &key,
            T2 &&value,
            size_t timeout = 0,
            std::function<void()> timeoutCallback = std::function<void()>())
{
    if (timeout > 0)
    {
        MapValue v;
        v.value = std::move(value);
        v.timeout = timeout;
        v.timeoutCallback_ = std::move(timeoutCallback);
        std::lock_guard<std::mutex> lock(mtx_);
        map_[key] = std::move(v);
        eraseAfter(timeout, key);
    }
    else
    {
        MapValue v;
        v.value = std::move(value);
        v.timeout = timeout;
        v.timeoutCallback_ = std::function<void()>();
        v.weakEntryPtr_ = WeakCallbackEntryPtr();
        std::lock_guard<std::mutex> lock(mtx_);
        map_[key] = std::move(v);
    }
}

Synopsis

#include <lib/inc/drogon/CacheMap.h>

void insert(const T1 &key, const T2 &value, size_t timeout=0, std::function< void()> timeoutCallback=std::function< void()>())

Description

Insert a key-value pair into the cache.

Parameters:

key - The key

value - The value

timeout - The timeout in seconds, if timeout > 0, the value will be erased within the 'timeout' seconds after the last access. If the timeout is zero, the value exists until being removed explicitly.

timeoutCallback - is called when the timeout expires.

Source

Lines 197-222 in lib/inc/drogon/CacheMap.h.

void insert(const T1 &key,
            const T2 &value,
            size_t timeout = 0,
            std::function<void()> timeoutCallback = std::function<void()>())
{
    if (timeout > 0)
    {
        MapValue v;
        v.value = value;
        v.timeout = timeout;
        v.timeoutCallback_ = std::move(timeoutCallback);
        std::lock_guard<std::mutex> lock(mtx_);
        map_[key] = std::move(v);
        eraseAfter(timeout, key);
    }
    else
    {
        MapValue v;
        v.value = value;
        v.timeout = timeout;
        v.timeoutCallback_ = std::function<void()>();
        v.weakEntryPtr_ = WeakCallbackEntryPtr();
        std::lock_guard<std::mutex> lock(mtx_);
        map_[key] = std::move(v);
    }
}





Add Discussion as Guest

Log in to DocsForge