|
|
| Cache (void)=default |
| | Default constructor for the Cache class.
|
| |
|
| ~Cache (void)=default |
| | Default destructor for the Cache class.
|
| |
|
| Cache (const Cache &other)=delete |
| | Deleted copy constructor to prevent copying of the cache.
|
| |
|
Cache & | operator= (const Cache &other)=delete |
| | Deleted copy assignment operator to prevent copying of the cache.
|
| |
|
| Cache (Cache &&other) noexcept=delete |
| | Deleted move constructor to prevent moving of the cache.
|
| |
|
Cache & | operator= (Cache &&other) noexcept=delete |
| | Deleted move assignment operator to prevent moving of the cache.
|
| |
| bool | contains (const Key &key) const |
| | Check if the cache contains a specific key.
|
| |
| std::optional< Entry > | get (const Key &key) const |
| | Retrieve the value associated with a specific key.
|
| |
| void | put (const Key &key, const Entry &value) |
| | Add or update a key-value pair in the cache.
|
| |
| void | put (Key &&key, Entry &&value) |
| | Add or update a key-value pair in the cache using move semantics.
|
| |
| template<typename... Args> |
| Entry & | emplace (const Key &key, Args &&...args) |
| | Emplace a new entry in the cache with the given key and constructor arguments.
|
| |
| template<typename... Args> |
| Entry & | emplace (Key &&key, Args &&...args) |
| | Emplace a new entry in the cache with the given key and constructor arguments using move semantics.
|
| |
| bool | erase (const Key &key) |
| | Remove an entry from the cache.
|
| |
| void | erase_if (const std::function< bool(const Key &, const Entry &)> &predicate) |
| | Remove entries from the cache based on a predicate.
|
| |
| void | apply (const std::function< void(const Key &, Entry &)> &function) |
| | Apply a function to each entry in the cache.
|
| |
| void | clear (void) |
| | Clear all entries from the cache.
|
| |
| std::map< Key, Entry, Compare >::size_type | size (void) const |
| | Get the number of entries in the cache.
|
| |
| bool | empty (void) const |
| | Check if the cache is empty.
|
| |
template<typename Key, CacheEntry Entry, typename Compare = std::less<Key>>
requires CacheKey<Key, Compare>
class utility::Cache< Key, Entry, Compare >
A thread-safe cache for storing key-value pairs.
This class provides a thread-safe cache that allows storing and retrieving key-value pairs. It uses a std::map internally to manage the entries and provides methods for adding, retrieving, and removing entries.
- Template Parameters
-
| Key | Type of the keys used in the cache. |
| Entry | Type of the values stored in the cache. |
| Compare | Comparison function type for ordering keys (default is std::less<Key>). |
Definition at line 68 of file cache.hpp.
template<typename Key , CacheEntry Entry, typename Compare = std::less<Key>>
template<typename... Args>
| Entry & utility::Cache< Key, Entry, Compare >::emplace |
( |
const Key & |
key, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Emplace a new entry in the cache with the given key and constructor arguments.
- Template Parameters
-
| Args | Types of the constructor arguments for the entry. |
- Parameters
-
| key | The key to associate with the new entry. |
| args | Constructor arguments for the entry. |
- Returns
- Reference to the newly emplaced entry.
- Note
- The returned reference is only valid while the calling thread holds no other cache operation; concurrent modification may invalidate it.
Definition at line 171 of file cache.hpp.
template<typename Key , CacheEntry Entry, typename Compare = std::less<Key>>
template<typename... Args>
| Entry & utility::Cache< Key, Entry, Compare >::emplace |
( |
Key && |
key, |
|
|
Args &&... |
args |
|
) |
| |
|
inline |
Emplace a new entry in the cache with the given key and constructor arguments using move semantics.
- Template Parameters
-
| Args | Types of the constructor arguments for the entry. |
- Parameters
-
| key | The key to associate with the new entry (moved). |
| args | Constructor arguments for the entry. |
- Returns
- Reference to the newly emplaced entry.
- Note
- The returned reference is only valid while the calling thread holds no other cache operation; concurrent modification may invalidate it.
Definition at line 190 of file cache.hpp.