hpx/cache/entries/lru_entry.hpp

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx
namespace util
namespace cache
namespace entries
template<typename Value>
class lru_entry : public hpx::util::cache::entries::entry<Value, lru_entry<Value>>
#include <hpx/cache/entries/lru_entry.hpp>

The lru_entry type can be used to store arbitrary values in a cache. Using this type as the cache’s entry type makes sure that the least recently used entries are discarded from the cache first.

Note

The lru_entry conforms to the CacheEntry concept.

Note

This type can be used to model a ‘most recently used’ cache policy if it is used with a std::greater as the caches’ UpdatePolicy (instead of the default std::less).

Template Parameters
  • Value: The data type to be stored in a cache. It has to be default constructible, copy constructible and less_than_comparable.

Public Functions

lru_entry()

Any cache entry has to be default constructible.

lru_entry(Value const &val)

Construct a new instance of a cache entry holding the given value.

lru_entry(Value &&val)

Construct a new instance of a cache entry holding the given value.

bool touch()

The function touch is called by a cache holding this instance whenever it has been requested (touched).

In the case of the LRU entry we store the time of the last access which will be used to compare the age of an entry during the invocation of the operator<().

Return

This function should return true if the cache needs to update it’s internal heap. Usually this is needed if the entry has been changed by touch() in a way influencing the sort order as mandated by the cache’s UpdatePolicy

constexpr time_point const &get_access_time() const

Returns the last access time of the entry.

Private Types

template<>
using base_type = entry<Value, lru_entry<Value>>
template<>
using time_point = std::chrono::steady_clock::time_point

Private Members

time_point access_time_

Friends

bool operator<(lru_entry const &lhs, lru_entry const &rhs)

Compare the ‘age’ of two entries. An entry is ‘older’ than another entry if it has been accessed less recently (LRU).