Is this generic implementation of cache thread safe (c++)?

Is this generic implementation of cache thread safe (c++)?

I wrote the following implementation of a generic cache, where&nbsp;func&nbsp;will provide the values (compute, read file, etc).&nbsp;<strong>Is it thread safe ?</strong>

I wrote the following implementation of a generic cache, where func will provide the values (compute, read file, etc). Is it thread safe ?

#pragma once
#include "stdafx.h"
#include <map>
#include <functional>
#include <mutex>

using namespace std;

template<class T1, class T2> class __declspec(dllexport) CacheOf { map<T1, T2> _cache; function<T2(T1)> _func; mutex CacheMtx; public: CacheOf(function<T2(T1)> func); ~CacheOf(); T2 Get(T1); void Clear(); };

template <class T1, class T2> CacheOf<T1, T2>::CacheOf(std::function<T2(T1)> func) { _func = func; }

template <class T1, class T2> CacheOf<T1, T2>::~CacheOf() { _cache.clear(); }

template <class T1, class T2> auto CacheOf<T1, T2>::Get(T1 key) -> T2 {

auto it = _cache.find(key);
T2 value;
if (it != _cache.end())
{
    value = it-&gt;second;
    return value;
}
value = _func(key);
{
    unique_lock&lt;mutex&gt; cachelock(CacheMtx);
    _cache.insert(pair&lt;T1, T2&gt;(key, value));
}
return value;

}

template <class T1, class T2> auto CacheOf<T1, T2>::Clear() -> void { _cache.clear(); }


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

C/C++ vs. Rust: A developer’s perspective

In this post, you'll see the difference between Rust and C/C++ in a developer’s perspective

Variable Introduction in C#[Bangla]

LIKE | COMMENT | SHARE | SUBSCRIBE A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in C# has a speci...