mod_servlet
C++Servlets
|
Implementation of LRU (least recently used) timed cache. More...
#include <lru_map.h>
Public Types | |
typedef linked_map< _Key, _Tp, _MT > | base_type |
Type of base linked_map | |
typedef base_type::key_type | key_type |
Container's key type. | |
typedef base_type::mapped_type | mapped_type |
Container's mapped type. | |
typedef base_type::value_type | value_type |
Container's value type: std::pair<const key_type&, mapped_type> | |
typedef base_type::allocator_type | allocator_type |
Container's allocator type. | |
typedef base_type::reference | reference |
value_type& | |
typedef base_type::const_reference | const_reference |
const value_type& | |
typedef base_type::pointer | pointer |
Pointer to value_type type. | |
typedef base_type::const_pointer | const_pointer |
Constant pointer to value_type type. | |
typedef base_type::size_type | size_type |
An unsigned integral type to represent the size of this container. | |
typedef base_type::difference_type | difference_type |
A signed integral type to represent distance between iterators. | |
typedef base_type::iterator | iterator |
Bidirectional iterator type. | |
typedef base_type::const_iterator | const_iterator |
Bidirectional constant iterator type. | |
typedef base_type::reverse_iterator | reverse_iterator |
Reverse iterator type. | |
typedef base_type::const_reverse_iterator | const_reverse_iterator |
Constant reverse iterator type. | |
![]() | |
typedef _Key | key_type |
Container's key type. | |
typedef _Tp | mapped_type |
Container's mapped type. | |
typedef std::pair< const _Key &, _Tp > | value_type |
Container's value type: std::pair<const key_type&, mapped_type> | |
typedef linked_map< _Key, _Tp, _MT > | self_type |
The type of this container. More... | |
typedef std::list< value_type > | list_type |
List type to maintain the order of elements. | |
typedef _MT | map_type |
Underlying map type. | |
typedef map_type::allocator_type | allocator_type |
Container's allocator type. | |
typedef value_type & | reference |
value_type& | |
typedef const value_type & | const_reference |
const value_type& | |
typedef value_type * | pointer |
Pointer to value_type type. | |
typedef const value_type * | const_pointer |
Constant pointer to value_type type. | |
typedef map_type::size_type | size_type |
An unsigned integral type to represent the size of this container. | |
typedef map_type::difference_type | difference_type |
A signed integral type to represent distance between iterators. | |
typedef list_type::iterator | iterator |
Bidirectional iterator type. | |
typedef list_type::const_iterator | const_iterator |
Bidirectional constant iterator type. | |
typedef list_type::reverse_iterator | reverse_iterator |
Reverse iterator type. | |
typedef list_type::const_reverse_iterator | const_reverse_iterator |
Constant reverse iterator type. | |
Public Member Functions | |
lru_map (std::size_t timeout_sec) | |
Constructs an empty container, with no elements. More... | |
lru_map (const lru_map &other) | |
Copy constructor. More... | |
lru_map (lru_map &&other) | |
Move constructor. More... | |
lru_map & | operator= (const lru_map &other) |
The copy assignment. More... | |
lru_map & | operator= (lru_map &&other) |
The move assignment. More... | |
void | set_timeout (std::size_t timeout_sec) |
Sets the timeout after which inactive elements will be purged from the cache. More... | |
template<typename KeyType > | |
bool | contains_key (const KeyType &key) const |
Tests whether value with a given key exists in this container. More... | |
void | clear () |
Clear content. More... | |
template<typename KeyType > | |
optional_ref< const mapped_type > | get (const KeyType &key) const |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<typename KeyType > | |
optional_ref< mapped_type > | get (const KeyType &key) |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<class... Args> | |
bool | put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<typename KeyType > | |
bool | erase (const KeyType &key) |
Erase element. More... | |
![]() | |
linked_map ()=default | |
Constructs an empty container, with no elements. | |
linked_map (const linked_map &m)=default | |
Copy constructor. More... | |
linked_map (linked_map &&m)=default | |
Move constructor. More... | |
linked_map & | operator= (const linked_map &m)=default |
The copy assignment. More... | |
linked_map & | operator= (linked_map &&m)=default |
The move assignment. More... | |
bool | empty () const noexcept |
Test whether container is empty. More... | |
size_type | size () const noexcept |
Returns the number of elements in the container. More... | |
template<typename KeyType > | |
bool | contains_key (const KeyType &key) const |
Tests whether value with a given key exists in this container. More... | |
void | clear () |
Clear content. More... | |
template<typename KeyType > | |
optional_ref< const mapped_type > | get (const KeyType &key) const |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<typename KeyType > | |
optional_ref< mapped_type > | get (const KeyType &key) |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<class... Args> | |
bool | put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<typename KeyType > | |
bool | erase (const KeyType &key) |
Erase element. More... | |
iterator | begin () noexcept |
Returns iterator to beginning of the container. More... | |
iterator | end () noexcept |
Return iterator to end of the container. More... | |
const_iterator | begin () const noexcept |
Returns constant iterator to beginning of the container. More... | |
const_iterator | end () const noexcept |
Return constant iterator to end of the container. More... | |
const_iterator | cbegin () const noexcept |
Returns constant iterator to beginning of the container. More... | |
const_iterator | cend () const noexcept |
Return constant iterator to end of the container. More... | |
reverse_iterator | rbegin () noexcept |
Return reverse iterator to reverse beginning. More... | |
reverse_iterator | rend () noexcept |
Return reverse iterator to reverse end. More... | |
const_reverse_iterator | rbegin () const noexcept |
Return constant reverse iterator to reverse beginning. More... | |
const_reverse_iterator | rend () const noexcept |
Return constant reverse iterator to reverse end. More... | |
const_reverse_iterator | crbegin () const noexcept |
Return constant reverse iterator to reverse beginning. More... | |
const_reverse_iterator | crend () const noexcept |
Return constant reverse iterator to reverse end. More... | |
Protected Member Functions | |
void | update (value_type &val) const override |
Updates access timestamp of the element. More... | |
void | purge () override |
Removes all the elements from the cache which has not been accessed for longer than this cache timeout. | |
Implementation of LRU (least recently used) timed cache.
This class keeps track of time when elements were accessed and removes them if the have not been accessed for longer than timeout
This is a synchronized container.
_Key | type of the key |
_Tp | type of the mapped value |
_MT | type of the base map for this class to inherit from. Currently it can be either std::map or std::unordered_map |
|
inline |
Constructs an empty container, with no elements.
The timeout argument is specified in seconds. After this number of seconds if element is not accessed it will be removed from this container.
timeout_sec | Expiration time for elements in this container. |
|
inline |
Copy constructor.
Constructs a container with a copy of each of the elements in other
.
other | linked map object to copy from. |
|
inline |
Move constructor.
Constructs a container that acquires the elements of other
by moving them.
other | linked map object to move from. |
|
inline |
Clear content.
Removes all elements from the container (which are destroyed), leaving the container with a size of 0
|
inline |
Tests whether value with a given key exists in this container.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to test. |
true
if a value with a given key exists in this container, false
otherwise.
|
inline |
Erase element.
Removes from the container a single element identified by a given key. Does nothing if the element with a given key is not found.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key of the element to remove. |
true
if the element was actually removed, false
otherwise.
|
inline |
Returns optional_ref
object to a value with a specified type, if that value exists and can be casted to the requested type.
If the value with a given key doesn't exists empty optional_ref will be returned.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to be searched for. |
optional_ref
to the found value, or empty reference if a value with a given key doesn't exists in this container. std::bad_any_cast | if the value is found, but couldn't be casted to the requested type |
|
inline |
Returns optional_ref
object to a value with a specified type, if that value exists and can be casted to the requested type.
If the value with a given key doesn't exists empty optional_ref will be returned.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to be searched for. |
optional_ref
to the found value, or empty reference if a value with a given key doesn't exists in this container. std::bad_any_cast | if the value is found, but couldn't be casted to the requested type |
|
inline |
The copy assignment.
Copies all the elements from other
into the container (with other
preserving its contents)
other | Cache object to copy from. |
|
inline |
The move assignment.
Moves the elements of other
into the container (other
is left in an unspecified but valid state).
other | Cache object to move from. |
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | arguments to create the mapped value |
bool
denoting whether the previous value was replaced.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether the previous value was replaced.
|
inline |
Sets the timeout after which inactive elements will be purged from the cache.
timeout_sec | Number of seconds after which inactive element will be removed. |
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, does nothing.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether insertion took place.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, does nothing.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether insertion took place.
|
inlineoverrideprotectedvirtual |
Updates access timestamp of the element.
val | Value for which to update the access timestamp. |
Reimplemented from servlet::linked_map< _Key, _Tp, _MT >.