ZNC  trunk
Public Member Functions | Protected Types | Protected Attributes | List of all members
TCacheMap< K, V > Class Template Reference

Insert an object with a time-to-live and check later if it still exists. More...

#include <Utils.h>

+ Collaboration diagram for TCacheMap< K, V >:

Public Member Functions

 TCacheMap (unsigned int uTTL=5000)
 
virtual ~TCacheMap ()
 
void AddItem (const K &Item)
 This function adds an item to the cache using the default time-to-live value. More...
 
void AddItem (const K &Item, unsigned int uTTL)
 This function adds an item to the cache using a custom time-to-live value. More...
 
void AddItem (const K &Item, const V &Val)
 This function adds an item to the cache using the default time-to-live value. More...
 
void AddItem (const K &Item, const V &Val, unsigned int uTTL)
 This function adds an item to the cache using a custom time-to-live value. More...
 
bool HasItem (const K &Item)
 Performs a Cleanup() and then checks to see if your item exists. More...
 
V * GetItem (const K &Item)
 Performs a Cleanup() and returns a pointer to the object, or nullptr. More...
 
bool RemItem (const K &Item)
 Removes a specific item from the cache. More...
 
void Cleanup ()
 Cycles through the queue removing all of the stale entries. More...
 
void Clear ()
 Clear all entries. More...
 
std::map< K, V > GetItems ()
 Returns all entries. More...
 
void SetTTL (unsigned int u)
 
unsigned int GetTTL () const
 

Protected Types

typedef std::pair< unsigned long long, V > value
 
typedef std::map< K, value >::iterator iterator
 

Protected Attributes

std::map< K, valuem_mItems
 Map of cached items. More...
 
unsigned int m_uTTL
 Default time-to-live duration. More...
 

Detailed Description

template<typename K, typename V = bool>
class TCacheMap< K, V >

Insert an object with a time-to-live and check later if it still exists.

Author
prozac proza.nosp@m.c@ro.nosp@m.ttenb.nosp@m.oy.c.nosp@m.om

Member Typedef Documentation

◆ iterator

template<typename K , typename V = bool>
typedef std::map<K, value>::iterator TCacheMap< K, V >::iterator
protected

◆ value

template<typename K , typename V = bool>
typedef std::pair<unsigned long long, V> TCacheMap< K, V >::value
protected

Constructor & Destructor Documentation

◆ TCacheMap()

template<typename K , typename V = bool>
TCacheMap< K, V >::TCacheMap ( unsigned int  uTTL = 5000)
inline

◆ ~TCacheMap()

template<typename K , typename V = bool>
virtual TCacheMap< K, V >::~TCacheMap ( )
inlinevirtual

Member Function Documentation

◆ AddItem() [1/4]

template<typename K , typename V = bool>
void TCacheMap< K, V >::AddItem ( const K &  Item)
inline

This function adds an item to the cache using the default time-to-live value.

Parameters
Itemthe item to add to the cache

References TCacheMap< K, V >::AddItem(), and TCacheMap< K, V >::m_uTTL.

Referenced by TCacheMap< K, V >::AddItem(), and CZNC::AddServerThrottle().

◆ AddItem() [2/4]

template<typename K , typename V = bool>
void TCacheMap< K, V >::AddItem ( const K &  Item,
const V &  Val 
)
inline

This function adds an item to the cache using the default time-to-live value.

Parameters
Itemthe item to add to the cache
ValThe value associated with the key Item

References TCacheMap< K, V >::AddItem(), and TCacheMap< K, V >::m_uTTL.

Referenced by TCacheMap< K, V >::AddItem().

◆ AddItem() [3/4]

template<typename K , typename V = bool>
void TCacheMap< K, V >::AddItem ( const K &  Item,
const V &  Val,
unsigned int  uTTL 
)
inline

This function adds an item to the cache using a custom time-to-live value.

Parameters
Itemthe item to add to the cache
ValThe value associated with the key Item
uTTLthe time-to-live for this specific item

References CUtils::GetMillTime(), TCacheMap< K, V >::m_mItems, and TCacheMap< K, V >::RemItem().

◆ AddItem() [4/4]

template<typename K , typename V = bool>
void TCacheMap< K, V >::AddItem ( const K &  Item,
unsigned int  uTTL 
)
inline

This function adds an item to the cache using a custom time-to-live value.

Parameters
Itemthe item to add to the cache
uTTLthe time-to-live for this specific item

References TCacheMap< K, V >::AddItem().

Referenced by TCacheMap< K, V >::AddItem().

◆ Cleanup()

template<typename K , typename V = bool>
void TCacheMap< K, V >::Cleanup ( )
inline

Cycles through the queue removing all of the stale entries.

References CUtils::GetMillTime(), and TCacheMap< K, V >::m_mItems.

Referenced by TCacheMap< K, V >::GetItem(), TCacheMap< K, V >::GetItems(), and TCacheMap< K, V >::HasItem().

◆ Clear()

template<typename K , typename V = bool>
void TCacheMap< K, V >::Clear ( )
inline

Clear all entries.

References TCacheMap< K, V >::m_mItems.

◆ GetItem()

template<typename K , typename V = bool>
V* TCacheMap< K, V >::GetItem ( const K &  Item)
inline

Performs a Cleanup() and returns a pointer to the object, or nullptr.

Parameters
ItemThe item to check for
Returns
Pointer to the item or nullptr if there is no suitable one

References TCacheMap< K, V >::Cleanup(), and TCacheMap< K, V >::m_mItems.

Referenced by CZNC::GetServerThrottle().

◆ GetItems()

template<typename K , typename V = bool>
std::map<K, V> TCacheMap< K, V >::GetItems ( )
inline

Returns all entries.

References TCacheMap< K, V >::Cleanup(), and TCacheMap< K, V >::m_mItems.

◆ GetTTL()

template<typename K , typename V = bool>
unsigned int TCacheMap< K, V >::GetTTL ( ) const
inline

◆ HasItem()

template<typename K , typename V = bool>
bool TCacheMap< K, V >::HasItem ( const K &  Item)
inline

Performs a Cleanup() and then checks to see if your item exists.

Parameters
ItemThe item to check for
Returns
true if item exists

References TCacheMap< K, V >::Cleanup(), and TCacheMap< K, V >::m_mItems.

◆ RemItem()

template<typename K , typename V = bool>
bool TCacheMap< K, V >::RemItem ( const K &  Item)
inline

Removes a specific item from the cache.

Parameters
ItemThe item to be removed
Returns
true if item existed and was removed, false if it never existed

References TCacheMap< K, V >::m_mItems.

Referenced by TCacheMap< K, V >::AddItem().

◆ SetTTL()

template<typename K , typename V = bool>
void TCacheMap< K, V >::SetTTL ( unsigned int  u)
inline

Member Data Documentation

◆ m_mItems

template<typename K , typename V = bool>
std::map<K, value> TCacheMap< K, V >::m_mItems
protected

◆ m_uTTL

template<typename K , typename V = bool>
unsigned int TCacheMap< K, V >::m_uTTL
protected

Default time-to-live duration.

Referenced by TCacheMap< K, V >::AddItem(), TCacheMap< K, V >::GetTTL(), and TCacheMap< K, V >::SetTTL().


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