UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TLruCache< KeyType, ValueType, KeyComp > Class Template Reference

#include <LruCache.h>

Classes

class  TBaseIterator
 
class  TConstIterator
 
class  TIterator
 

Public Member Functions

 TLruCache ()
 
 TLruCache (int32 InMaxNumElements)
 
 ~TLruCache ()
 
void Add (const KeyType &Key, const ValueType &Value)
 
ValueType & AddUninitialized_GetRef (const KeyType &Key)
 
UE_FORCEINLINE_HINT bool Contains (const KeyType &Key) const
 
template<typename Predicate >
bool ContainsByPredicate (Predicate Pred) const
 
void Empty (int32 InMaxNumElements=0)
 
template<typename Predicate >
TArray< ValueType > FilterByPredicate (Predicate Pred) const
 
const ValueType * Find (const KeyType &Key) const
 
ValueType * Find (const KeyType &Key)
 
const ValueType & FindChecked (const KeyType &Key) const
 
ValueType & FindChecked (const KeyType &Key)
 
ValueType FindRef (const KeyType &Key) const
 
ValueType * FindAndTouch (const KeyType &Key)
 
ValueType & FindAndTouchChecked (const KeyType &Key)
 
ValueType FindAndTouchRef (const KeyType &Key)
 
template<typename Predicate >
const ValueType * FindByPredicate (Predicate Pred) const
 
void GetKeys (TArray< KeyType > &OutKeys) const
 
UE_FORCEINLINE_HINT int32 Max () const
 
bool IsEmpty () const
 
UE_FORCEINLINE_HINT int32 Num () const
 
void Remove (const KeyType &Key)
 
template<typename Predicate >
int32 RemoveByPredicate (Predicate Pred)
 
ValueType RemoveLeastRecent ()
 
KeyType GetLeastRecentKey () const
 
TIterator begin ()
 
TConstIterator begin () const
 
TIterator end ()
 
TConstIterator end () const
 

Protected Member Functions

void MarkAsRecent (FCacheEntry &Entry)
 
void Remove (FCacheEntry *Entry)
 

Detailed Description

template<typename KeyType, typename ValueType, typename KeyComp = DefaultKeyComparer<KeyType>>
class TLruCache< KeyType, ValueType, KeyComp >

Implements a Least Recently Used (LRU) cache.

Parameters
KeyTypeThe type of cache entry keys.
ValueTypeThe type of cache entry values.
KeyFuncsOptional functions for comparing keys in the lookup set (see BaseKeyFuncs in Set.h).

Constructor & Destructor Documentation

◆ TLruCache() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TLruCache< KeyType, ValueType, KeyComp >::TLruCache ( )
inline

Default constructor (empty cache that cannot hold any values).

◆ TLruCache() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TLruCache< KeyType, ValueType, KeyComp >::TLruCache ( int32  InMaxNumElements)
inline

Create and initialize a new instance.

Parameters
InMaxNumElementsThe maximum number of elements this cache can hold.

◆ ~TLruCache()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TLruCache< KeyType, ValueType, KeyComp >::~TLruCache ( )
inline

Destructor.

Member Function Documentation

◆ Add()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::Add ( const KeyType &  Key,
const ValueType &  Value 
)
inline

Add an entry to the cache.

If an entry with the specified key already exists in the cache, the value of the existing entry will be updated. The added or updated entry will be marked as the most recently used one.

Parameters
KeyThe entry's lookup key.
ValueThe entry's value.
See also
AddUninitialized_GetRef,Empty, Find, GetKeys, Remove

◆ AddUninitialized_GetRef()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType & TLruCache< KeyType, ValueType, KeyComp >::AddUninitialized_GetRef ( const KeyType &  Key)
inline

Add an entry to the cache.

If an entry with the specified key already exists in the cache, the value of the existing entry will be returned. The added or updated entry will be marked as the most recently used one.

Parameters
KeyThe entry's lookup key.
Returns
The entry's value.
See also
Add, Empty, Find, GetKeys, Remove

◆ begin() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TIterator TLruCache< KeyType, ValueType, KeyComp >::begin ( )
inline

◆ begin() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TConstIterator TLruCache< KeyType, ValueType, KeyComp >::begin ( ) const
inline

◆ Contains()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
UE_FORCEINLINE_HINT bool TLruCache< KeyType, ValueType, KeyComp >::Contains ( const KeyType &  Key) const
inline

Check whether an entry with the specified key is in the cache.

Parameters
KeyThe key of the entry to check.
Returns
true if the entry is in the cache, false otherwise.
See also
Add, ContainsByPredicate, Empty, FilterByPredicate, Find, GetKeys, Remove

◆ ContainsByPredicate()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
template<typename Predicate >
bool TLruCache< KeyType, ValueType, KeyComp >::ContainsByPredicate ( Predicate  Pred) const
inline

Check whether an entry for which a predicate returns true is in the cache.

Parameters
PredThe predicate functor to apply to each entry.
Returns
true if at least one matching entry is in the cache, false otherwise.
See also
Contains, FilterByPredicate, FindByPredicate, RemoveByPredicate

◆ Empty()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::Empty ( int32  InMaxNumElements = 0)
inline

Empty the cache.

Parameters
InMaxNumElementsThe maximum number of elements this cache can hold (default = 0).
See also
Add, Find, GetKeys, Max, Num, Remove

◆ end() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TIterator TLruCache< KeyType, ValueType, KeyComp >::end ( )
inline

◆ end() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
TConstIterator TLruCache< KeyType, ValueType, KeyComp >::end ( ) const
inline

◆ FilterByPredicate()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
template<typename Predicate >
TArray< ValueType > TLruCache< KeyType, ValueType, KeyComp >::FilterByPredicate ( Predicate  Pred) const
inline

Filter the entries in the cache using a predicate.

Parameters
PredThe predicate functor to apply to each entry.
Returns
Collection of values for which the predicate returned true.
See also
ContainsByPredicate, FindByPredicate, Find, RemoveByPredicate

◆ Find() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType * TLruCache< KeyType, ValueType, KeyComp >::Find ( const KeyType &  Key)
inline

Find the value of the entry with the specified key.

Parameters
KeyThe key of the entry to get.
Returns
Pointer to the value, or nullptr if not found.
See also
Add, Contains, Empty, FindAndTouch, GetKeys, Remove

◆ Find() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
const ValueType * TLruCache< KeyType, ValueType, KeyComp >::Find ( const KeyType &  Key) const
inline

Find the value of the entry with the specified key.

Parameters
KeyThe key of the entry to get.
Returns
Pointer to the value, or nullptr if not found.
See also
Add, Contains, Empty, FindAndTouch, GetKeys, Remove

◆ FindAndTouch()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType * TLruCache< KeyType, ValueType, KeyComp >::FindAndTouch ( const KeyType &  Key)
inline

Find the value of the entry with the specified key and mark it as the most recently used.

Parameters
KeyThe key of the entry to get.
Returns
Pointer to the value, or nullptr if not found.
See also
Add, Contains, Empty, Find, GetKeys, Remove

◆ FindAndTouchChecked()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType & TLruCache< KeyType, ValueType, KeyComp >::FindAndTouchChecked ( const KeyType &  Key)
inline

Find the value of the entry with the specified key and mark it as the most recently used.

Parameters
KeyThe key of the entry to get.
Returns
Pointer to the value, or triggers an assertion if the key does not exist.

◆ FindAndTouchRef()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType TLruCache< KeyType, ValueType, KeyComp >::FindAndTouchRef ( const KeyType &  Key)
inline

Find the value of the entry with the specified key and mark it as the most recently used.

Parameters
KeyThe key of the entry to get.
Returns
Copy of the value, or the default value for the ValueType if the key does not exist.

◆ FindByPredicate()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
template<typename Predicate >
const ValueType * TLruCache< KeyType, ValueType, KeyComp >::FindByPredicate ( Predicate  Pred) const
inline

Find the value of an entry using a predicate.

Parameters
PredThe predicate functor to apply to each entry.
Returns
Pointer to value for which the predicate returned true, or nullptr if not found.
See also
ContainsByPredicate, FilterByPredicate, RemoveByPredicate

◆ FindChecked() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType & TLruCache< KeyType, ValueType, KeyComp >::FindChecked ( const KeyType &  Key)
inline

Find the value of the entry with the specified key.

Parameters
KeyThe key of the entry to get.
Returns
Reference to the value, or triggers an assertion if the key does not exist.

◆ FindChecked() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
const ValueType & TLruCache< KeyType, ValueType, KeyComp >::FindChecked ( const KeyType &  Key) const
inline

Find the value of the entry with the specified key.

Parameters
KeyThe key of the entry to get.
Returns
Reference to the value, or triggers an assertion if the key does not exist.

◆ FindRef()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType TLruCache< KeyType, ValueType, KeyComp >::FindRef ( const KeyType &  Key) const
inline

Find the value of the entry with the specified key.

Parameters
KeyThe key of the entry to get.
Returns
Copy of the value, or the default value for the ValueType if the key does not exist.

◆ GetKeys()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::GetKeys ( TArray< KeyType > &  OutKeys) const
inline

Find the keys of all cached entries.

Parameters
OutKeysWill contain the collection of keys.
See also
Add, Empty, Find

◆ GetLeastRecentKey()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
KeyType TLruCache< KeyType, ValueType, KeyComp >::GetLeastRecentKey ( ) const
inline

Return the least recent element key from the cache.

Returns
Copy of least recent key.

◆ IsEmpty()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
bool TLruCache< KeyType, ValueType, KeyComp >::IsEmpty ( ) const
inline

Returns true if the cache is empty and contains no elements.

Returns
True if the cache is empty.
See also
Num

◆ MarkAsRecent()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::MarkAsRecent ( FCacheEntry &  Entry)
inlineprotected

Mark the given entry as recently used.

Parameters
EntryThe entry to mark.

◆ Max()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
UE_FORCEINLINE_HINT int32 TLruCache< KeyType, ValueType, KeyComp >::Max ( ) const
inline

Get the maximum number of entries in the cache.

Returns
Maximum number of entries.
See also
Empty, Num

◆ Num()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
UE_FORCEINLINE_HINT int32 TLruCache< KeyType, ValueType, KeyComp >::Num ( ) const
inline

Get the number of entries in the cache.

Returns
Number of entries.
See also
Empty, Max

◆ Remove() [1/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::Remove ( const KeyType &  Key)
inline

Remove all entries with the specified key from the cache.

Parameters
KeyThe key of the entries to remove.
See also
Add, Empty, Find, RemoveByPredicate

◆ Remove() [2/2]

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
void TLruCache< KeyType, ValueType, KeyComp >::Remove ( FCacheEntry *  Entry)
inlineprotected

Remove the specified entry from the cache.

Parameters
EntryThe entry to remove.

◆ RemoveByPredicate()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
template<typename Predicate >
int32 TLruCache< KeyType, ValueType, KeyComp >::RemoveByPredicate ( Predicate  Pred)
inline

Remove all entries using a predicate.

Parameters
PredThe predicate function to apply to each entry.
Returns
Number of removed entries.
See also
ContainsByPredicate, FilterByPredicate, FindByPredicate, Remove

◆ RemoveLeastRecent()

template<typename KeyType , typename ValueType , typename KeyComp = DefaultKeyComparer<KeyType>>
ValueType TLruCache< KeyType, ValueType, KeyComp >::RemoveLeastRecent ( )
inline

Remove and return the least recent element from the cache.

Returns
Copy of removed value.

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