Twitch SDK (Internal)
Classes | Public Types | Public Member Functions | Protected Types | Protected Attributes | List of all members
ttv::Cache< KEY_TYPE, VALUE_TYPE > Class Template Reference

#include <cache.h>

Classes

struct  CacheEntry
 

Public Types

typedef std::function< void(CacheEntry &entry)> VisitorFunc
 

Public Member Functions

 Cache ()
 
void SetExpiryAge (uint64_t age)
 
uint32_t GetSize () const
 
void PurgeUnused (uint64_t olderThan)
 
void PurgeExpired ()
 
void Clear ()
 
bool MarkEntryUsed (const KEY_TYPE &key)
 
bool MarkEntryNeverUnused (const KEY_TYPE &key)
 
bool MarkEntryNeverExpires (const KEY_TYPE &key)
 
bool SetEntryExpiryTime (const KEY_TYPE &key, uint64_t time)
 
bool ExpireEntry (const KEY_TYPE &key)
 
void ExpireAll ()
 
void SetEntry (const KEY_TYPE &key, VALUE_TYPE data)
 
void RemoveEntry (const KEY_TYPE &key)
 
bool GetEntry (const KEY_TYPE &key, VALUE_TYPE &result)
 
void GetKeys (std::vector< KEY_TYPE > &result)
 
bool ContainsEntry (const KEY_TYPE &key) const
 
void ForEach (VisitorFunc func)
 
bool HasExpiredEntries () const
 
void ForEachExpired (VisitorFunc func)
 

Protected Types

typedef std::unordered_map< KEY_TYPE, CacheEntryMapType
 

Protected Attributes

MapType mCache
 The mapping of key to the data. More...
 
uint64_t mExpiryAge
 The amount of time after which entries expire. More...
 

Detailed Description

template<typename KEY_TYPE, typename VALUE_TYPE>
class ttv::Cache< KEY_TYPE, VALUE_TYPE >

A helper class which provides data caching. Designed to store std::shared_ptrs as value_types; when storing primitives as value_types, be aware that ForEach iterates over a copy of the cache.

Member Typedef Documentation

◆ MapType

template<typename KEY_TYPE, typename VALUE_TYPE>
typedef std::unordered_map<KEY_TYPE, CacheEntry> ttv::Cache< KEY_TYPE, VALUE_TYPE >::MapType
protected

◆ VisitorFunc

template<typename KEY_TYPE, typename VALUE_TYPE>
typedef std::function<void(CacheEntry& entry)> ttv::Cache< KEY_TYPE, VALUE_TYPE >::VisitorFunc

Constructor & Destructor Documentation

◆ Cache()

template<typename KEY_TYPE, typename VALUE_TYPE>
ttv::Cache< KEY_TYPE, VALUE_TYPE >::Cache ( )
inline

Member Function Documentation

◆ Clear()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::Clear ( )
inline

Clears the cache.

◆ ContainsEntry()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::ContainsEntry ( const KEY_TYPE &  key) const
inline

Determines if any data is cached under the given key.

◆ ExpireAll()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::ExpireAll ( )
inline

Expires all entries immediately.

◆ ExpireEntry()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::ExpireEntry ( const KEY_TYPE &  key)
inline

Expire the entry immediately.

Returns
true if the entry was found, false otherwise.

◆ ForEach()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::ForEach ( VisitorFunc  func)
inline

Visits each entry in the cache.

◆ ForEachExpired()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::ForEachExpired ( VisitorFunc  func)
inline

Visit each expired entry in the cache.

◆ GetEntry()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::GetEntry ( const KEY_TYPE &  key,
VALUE_TYPE &  result 
)
inline

Retrieves the value from the cache.

Returns
true if entry was found, false otherwise.

◆ GetKeys()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::GetKeys ( std::vector< KEY_TYPE > &  result)
inline

Retrieves the set of keys for cached values.

◆ GetSize()

template<typename KEY_TYPE, typename VALUE_TYPE>
uint32_t ttv::Cache< KEY_TYPE, VALUE_TYPE >::GetSize ( ) const
inline

Returns the number of entries in the cache.

◆ HasExpiredEntries()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::HasExpiredEntries ( ) const
inline

◆ MarkEntryNeverExpires()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::MarkEntryNeverExpires ( const KEY_TYPE &  key)
inline

Marks the entry as never expiring. This is reset by setting the entry again or manipulating the expiry time with other methods.

Returns
true if the entry was found, false otherwise.

◆ MarkEntryNeverUnused()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::MarkEntryNeverUnused ( const KEY_TYPE &  key)
inline

Marks the entry as never being unused so it will never be purged. This is reset by MarkEntryUsed().

Returns
true if the entry was found, false otherwise.

◆ MarkEntryUsed()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::MarkEntryUsed ( const KEY_TYPE &  key)
inline

Marks the entry as recently used.

Returns
true if the entry was found, false otherwise.

◆ PurgeExpired()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::PurgeExpired ( )
inline

Removes items from the cache whose expiry time has elapsed.

◆ PurgeUnused()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::PurgeUnused ( uint64_t  olderThan)
inline

Removes items from the cache that have not been used for the given amount of time.

◆ RemoveEntry()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::RemoveEntry ( const KEY_TYPE &  key)
inline

Explicitly removes the given value from the cache.

◆ SetEntry()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::SetEntry ( const KEY_TYPE &  key,
VALUE_TYPE  data 
)
inline

Caches the given value.

◆ SetEntryExpiryTime()

template<typename KEY_TYPE, typename VALUE_TYPE>
bool ttv::Cache< KEY_TYPE, VALUE_TYPE >::SetEntryExpiryTime ( const KEY_TYPE &  key,
uint64_t  time 
)
inline

Explicitly sets the expiry time for a given cache item.

Returns
true if the entry was found, false otherwise.

◆ SetExpiryAge()

template<typename KEY_TYPE, typename VALUE_TYPE>
void ttv::Cache< KEY_TYPE, VALUE_TYPE >::SetExpiryAge ( uint64_t  age)
inline

Sets the amount of time after which entries will expire. Modifying this while entries exist in the cache will not affect existing entries.

Member Data Documentation

◆ mCache

template<typename KEY_TYPE, typename VALUE_TYPE>
MapType ttv::Cache< KEY_TYPE, VALUE_TYPE >::mCache
protected

The mapping of key to the data.

◆ mExpiryAge

template<typename KEY_TYPE, typename VALUE_TYPE>
uint64_t ttv::Cache< KEY_TYPE, VALUE_TYPE >::mExpiryAge
protected

The amount of time after which entries expire.


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