Skip to content

The Put and Erase functions in the cache.hpp file can reduce the granularity of locks #37

@userwang12

Description

@userwang12

like this
`
void Put(const Key &key, const Value &value) noexcept
{
auto elem_it = FindElem(key);

    {
        operation_guard lock{safe_op}; 
        if (elem_it == cache_items_map.end())
        {
            // add new element to the cache
            if (cache_items_map.size() + 1 > max_cache_size)
            {
                auto disp_candidate_key = cache_policy.ReplCandidate();
                Erase(disp_candidate_key);
            }

            Insert(key, std::move(value));
        }
        else
        {
            // update previous value
            Update(key, std::move(value));
        }
    }
}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions