TARAXA
ExpirationCache< Key > Class Template Reference

#include <util.hpp>

Public Member Functions

 ExpirationCache (uint32_t max_size, uint32_t delete_step)
 
bool insert (Key const &key)
 Inserts key into the cache map. In case provided key is already in cache, only shared lock is acquired and function returns false. This means insert does not need to be used together with count() to save the performance by not acquiring unique lock. More...
 
bool contains (Key const &key) const
 
void erase (Key const &key)
 
std::size_t count (Key const &key) const
 
std::size_t size () const
 
void clear ()
 

Protected Attributes

std::unordered_set< Key > cache_
 
const uint32_t kMaxSize
 
const uint32_t kDeleteStep
 
std::shared_mutex mtx_
 

Private Attributes

std::deque< Key > expiration_
 

Constructor & Destructor Documentation

◆ ExpirationCache()

template<class Key >
ExpirationCache< Key >::ExpirationCache ( uint32_t  max_size,
uint32_t  delete_step 
)
inline

Member Function Documentation

◆ clear()

template<class Key >
void ExpirationCache< Key >::clear ( )
inline

◆ contains()

template<class Key >
bool ExpirationCache< Key >::contains ( Key const &  key) const
inline

◆ count()

template<class Key >
std::size_t ExpirationCache< Key >::count ( Key const &  key) const
inline

◆ erase()

template<class Key >
void ExpirationCache< Key >::erase ( Key const &  key)
inline

◆ insert()

template<class Key >
bool ExpirationCache< Key >::insert ( Key const &  key)
inline

Inserts key into the cache map. In case provided key is already in cache, only shared lock is acquired and function returns false. This means insert does not need to be used together with count() to save the performance by not acquiring unique lock.

Parameters
key
Returns
true if actual insertion took place, otherwise false

◆ size()

template<class Key >
std::size_t ExpirationCache< Key >::size ( ) const
inline

Member Data Documentation

◆ cache_

template<class Key >
std::unordered_set<Key> ExpirationCache< Key >::cache_
protected

◆ expiration_

template<class Key >
std::deque<Key> ExpirationCache< Key >::expiration_
private

◆ kDeleteStep

template<class Key >
const uint32_t ExpirationCache< Key >::kDeleteStep
protected

◆ kMaxSize

template<class Key >
const uint32_t ExpirationCache< Key >::kMaxSize
protected

◆ mtx_

template<class Key >
std::shared_mutex ExpirationCache< Key >::mtx_
mutableprotected

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