The class template ConcurrentCache describes an associative static container that allows the concurrent access to the stored data. More...
Inherits Policy< Container >.
Public Member Functions | |
template<class F , class... Args> | |
data_type const & | get (key_type const &key, F &&f, Args &&... args) const |
Return the data associated to the key . More... | |
The class template ConcurrentCache describes an associative static container that allows the concurrent access to the stored data.
Cache data of arbitray type that needs initialization on the first access. The data is thereby initialized thread-wise or globally only once, and guarantees that you always get initialized data.
Key | The type of key to access the data. |
Data | The type of the data stored in the cache. The behaviur is undefined if Data is not the same type as Container::mapped_type. |
Policy | A policy class template implementing the method get_or_init() . Three implementations are provided: ConsecutivePolicy, ThreadLocalPolicy and StaticLockedPolicy. By default, if no policy class template is specified, the ThreadLocalPolicy is used. |
Container | The type of the underlying associative container to use to store the data. The container must satisfy the requirements of AssociativeContainer. The standard containers std::map and std::unordered_map satisfie this requirement. By default, if not container class is specified, the standard container std::unordered_map<Key,Data> is used. Note, an unordered_map requires the key to be hashable. |
The Policy
class template is a template parametrizable with the container type, that provides a static get_or_init()
method that is called with the key, and a functor for creation of new data elements.
|
inline |
Return the data associated to the key
.
Return the data associated to key. If no data is found, create a new entry in the container with a value obtained from the functor, by calling f(key, args...)
.
f | A functor of signature data_type(key_type, Args...) |
args... | Arguments passed additionally to the functor f |