26 #ifndef NFD_DAEMON_TABLE_CS_POLICY_HPP
27 #define NFD_DAEMON_TABLE_CS_POLICY_HPP
49 BOOST_ASSERT(!policyName.empty());
50 auto r = getRegistry().insert_or_assign(std::string(policyName), [] {
return make_unique<P>(); });
51 BOOST_VERIFY(r.second);
58 static unique_ptr<Policy>
59 create(
const std::string& policyName);
64 static std::set<std::string>
200 Policy(std::string_view policyName);
205 using CreateFunc = std::function<unique_ptr<Policy>()>;
206 using Registry = std::map<std::string, CreateFunc>;
212 const std::string m_policyName;
222 #define NFD_REGISTER_CS_POLICY(P) \
223 static class NfdAuto ## P ## CsPolicyRegistrationClass \
226 NfdAuto ## P ## CsPolicyRegistrationClass() \
228 ::nfd::cs::Policy::registerPolicy<P>(); \
230 } g_nfdAuto ## P ## CsPolicyRegistrationVariable
Implements the Content Store.
Represents a CS replacement policy.
virtual void doAfterInsert(EntryRef i)=0
Invoked after a new entry is created in CS.
virtual void doAfterRefresh(EntryRef i)=0
Invoked after an existing entry is refreshed by same Data.
void setLimit(size_t nMaxEntries)
Sets hard limit (in number of entries).
void beforeUse(EntryRef i)
Invoked by CS before an entry is used to match a lookup.
void afterInsert(EntryRef i)
Invoked by CS after a new entry is inserted.
static std::set< std::string > getPolicyNames()
Returns a list of available policy names.
static void registerPolicy(std::string_view policyName=P::POLICY_NAME)
static unique_ptr< Policy > create(const std::string &policyName)
Returns a cs::Policy identified by policyName, or nullptr if policyName is unknown.
virtual void evictEntries()=0
Evicts zero or more entries.
virtual void doBeforeErase(EntryRef i)=0
Invoked before an entry is erased due to management command.
void setCs(Cs *cs) noexcept
Sets the associated CS instance.
Cs * getCs() const noexcept
Returns a pointer to the associated CS instance.
virtual ~Policy()=default
virtual void doBeforeUse(EntryRef i)=0
Invoked before an entry is used to match a lookup.
void beforeErase(EntryRef i)
Invoked by CS before an entry is erased due to management command.
const std::string & getName() const noexcept
Policy(std::string_view policyName)
Table::const_iterator EntryRef
A reference to a CS entry.
size_t getLimit() const noexcept
Gets hard limit (in number of entries).
signal::Signal< Policy, EntryRef > beforeEvict
Signal emitted when an entry is being evicted.
void afterRefresh(EntryRef i)
Invoked by CS after an existing entry is refreshed by same Data.