Function findAndFetch

Synopsis

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

bool findAndFetch(const T1 &key, T2 &value)

Description

Atomically find and get the value of a keyword.

Return true when the value is found, and the value is assigned to the value argument.

Source

Lines 266-283 in lib/inc/drogon/CacheMap.h.

bool findAndFetch(const T1 &key, T2 &value)
{
    size_t timeout = 0;
    bool flag = false;
    std::lock_guard<std::mutex> lock(mtx_);
    auto iter = map_.find(key);
    if (iter != map_.end())
    {
        timeout = iter->second.timeout;
        flag = true;
        value = iter->second.value;
    }
    if (timeout > 0)
        eraseAfter(timeout, key);
    return flag;
}





Add Discussion as Guest

Log in to DocsForge