DocWire SDK
DocWire SDK: Award-winning modern data processing in C++20. SourceForge Community Choice & Microsoft support. AI-driven processing. Supports nearly 100 data formats, including email boxes and OCR. Boost efficiency in text extraction, web data extraction, data mining, document analysis. Offline processing possible for security and confidentiality
docwire::lru_memory_cache< Key, Value > Class Template Reference

Least Recently Used (LRU) cache with fixed memory size. More...

#include <lru_memory_cache.h>

Public Member Functions

 lru_memory_cache (size_t max_size=std::numeric_limits< size_t >::max())
 Constructs LRU cache with specified maximum size. More...
 
Value & get_or_create (const Key &key, const std::function< Value(const Key &)> &producer)
 Returns value for specified key. If key is not in the cache, it calls producer function to create value for the key. More...
 

Detailed Description

template<typename Key, typename Value>
class docwire::lru_memory_cache< Key, Value >

Least Recently Used (LRU) cache with fixed memory size.

Cache stores key-value pairs. If cache reaches its maximum size, it evicts least recently used entry from the cache.

Template Parameters
KeyKey type
ValueValue type

Definition at line 33 of file lru_memory_cache.h.

Constructor & Destructor Documentation

◆ lru_memory_cache()

template<typename Key , typename Value >
docwire::lru_memory_cache< Key, Value >::lru_memory_cache ( size_t  max_size = std::numeric_limits<size_t>::max())
inlineexplicit

Constructs LRU cache with specified maximum size.

Parameters
max_sizeMaximum size of the cache. Default is std::numeric_limits<size_t>::max(), which means there is no limit.

Definition at line 41 of file lru_memory_cache.h.

Member Function Documentation

◆ get_or_create()

template<typename Key , typename Value >
Value& docwire::lru_memory_cache< Key, Value >::get_or_create ( const Key &  key,
const std::function< Value(const Key &)> &  producer 
)
inline

Returns value for specified key. If key is not in the cache, it calls producer function to create value for the key.

Parameters
keyKey for which value is requested
producerFunction that creates value for specified key if key is not in the cache
Returns
Reference to value for specified key

Definition at line 52 of file lru_memory_cache.h.


The documentation for this class was generated from the following file: