Represents a CS replacement policy. More...
#include <daemon/table/cs-policy.hpp>
Public Types | |
using | EntryRef = Table::const_iterator |
A reference to a CS entry. More... | |
Public Member Functions | |
virtual | ~Policy ()=default |
void | afterInsert (EntryRef i) |
Invoked by CS after a new entry is inserted. More... | |
void | afterRefresh (EntryRef i) |
Invoked by CS after an existing entry is refreshed by same Data. More... | |
void | beforeErase (EntryRef i) |
Invoked by CS before an entry is erased due to management command. More... | |
void | beforeUse (EntryRef i) |
Invoked by CS before an entry is used to match a lookup. More... | |
Cs * | getCs () const noexcept |
Returns a pointer to the associated CS instance. More... | |
size_t | getLimit () const noexcept |
Gets hard limit (in number of entries). More... | |
const std::string & | getName () const noexcept |
void | setCs (Cs *cs) noexcept |
Sets the associated CS instance. More... | |
void | setLimit (size_t nMaxEntries) |
Sets hard limit (in number of entries). More... | |
Static Public Member Functions | |
static unique_ptr< Policy > | create (const std::string &policyName) |
Returns a cs::Policy identified by policyName , or nullptr if policyName is unknown. More... | |
static std::set< std::string > | getPolicyNames () |
Returns a list of available policy names. More... | |
template<typename P > | |
static void | registerPolicy (std::string_view policyName=P::POLICY_NAME) |
Public Attributes | |
signal::Signal< Policy, EntryRef > | beforeEvict |
Signal emitted when an entry is being evicted. More... | |
Protected Member Functions | |
Policy (std::string_view policyName) | |
virtual void | doAfterInsert (EntryRef i)=0 |
Invoked after a new entry is created in CS. More... | |
virtual void | doAfterRefresh (EntryRef i)=0 |
Invoked after an existing entry is refreshed by same Data. More... | |
virtual void | doBeforeErase (EntryRef i)=0 |
Invoked before an entry is erased due to management command. More... | |
virtual void | doBeforeUse (EntryRef i)=0 |
Invoked before an entry is used to match a lookup. More... | |
virtual void | evictEntries ()=0 |
Evicts zero or more entries. More... | |
Represents a CS replacement policy.
Definition at line 42 of file cs-policy.hpp.
using nfd::cs::Policy::EntryRef = Table::const_iterator |
A reference to a CS entry.
operator<
of EntryRef compares the Data name enclosed in the Entry. Definition at line 117 of file cs-policy.hpp.
|
virtualdefault |
|
explicitprotected |
Definition at line 61 of file cs-policy.cpp.
void nfd::cs::Policy::afterInsert | ( | EntryRef | i | ) |
Invoked by CS after a new entry is inserted.
The policy may evict entries if necessary. During this process, i
might be evicted.
Definition at line 75 of file cs-policy.cpp.
void nfd::cs::Policy::afterRefresh | ( | EntryRef | i | ) |
Invoked by CS after an existing entry is refreshed by same Data.
The policy may witness this refresh to make better eviction decisions in the future.
Definition at line 82 of file cs-policy.cpp.
void nfd::cs::Policy::beforeErase | ( | EntryRef | i | ) |
Invoked by CS before an entry is erased due to management command.
Definition at line 89 of file cs-policy.cpp.
void nfd::cs::Policy::beforeUse | ( | EntryRef | i | ) |
Invoked by CS before an entry is used to match a lookup.
The policy may witness this usage to make better eviction decisions in the future.
Definition at line 96 of file cs-policy.cpp.
|
static |
Returns a cs::Policy identified by policyName
, or nullptr if policyName
is unknown.
Definition at line 45 of file cs-policy.cpp.
|
protectedpure virtual |
Invoked after a new entry is created in CS.
When overridden in a subclass, a policy implementation should decide whether to accept i
. If i
is accepted, it should be inserted into a cleanup index. Otherwise, beforeEvict
signal should be emitted with i
to inform CS to erase the entry. A policy implementation may decide to evict other entries by emitting beforeEvict
signal, in order to keep CS size under limit.
|
protectedpure virtual |
Invoked after an existing entry is refreshed by same Data.
When overridden in a subclass, a policy implementation may witness this operation and adjust its cleanup index.
|
protectedpure virtual |
Invoked before an entry is erased due to management command.
When overridden in a subclass, a policy implementation should erase i
from its cleanup index without emitted afterErase
signal.
|
protectedpure virtual |
Invoked before an entry is used to match a lookup.
When overridden in a subclass, a policy implementation may witness this operation and adjust its cleanup index.
|
protectedpure virtual |
Evicts zero or more entries.
|
inlinenoexcept |
Returns a pointer to the associated CS instance.
Definition at line 81 of file cs-policy.hpp.
|
inlinenoexcept |
Gets hard limit (in number of entries).
Definition at line 99 of file cs-policy.hpp.
|
inlinenoexcept |
Definition at line 72 of file cs-policy.hpp.
|
static |
Returns a list of available policy names.
Definition at line 53 of file cs-policy.cpp.
|
inlinestatic |
Definition at line 47 of file cs-policy.hpp.
|
inlinenoexcept |
Sets the associated CS instance.
Definition at line 90 of file cs-policy.hpp.
void nfd::cs::Policy::setLimit | ( | size_t | nMaxEntries | ) |
Sets hard limit (in number of entries).
The policy may evict entries if necessary.
Definition at line 67 of file cs-policy.cpp.
Signal emitted when an entry is being evicted.
A policy implementation should emit this signal to cause CS to erase an entry from its index. CS should connect to this signal and erase the entry upon signal emission.
Definition at line 124 of file cs-policy.hpp.