38 static unique_ptr<Policy>
47 m_policy->setLimit(nMaxPackets);
53 if (!m_shouldAdmit || m_policy->getLimit() == 0) {
62 if (policy == lp::CachePolicyType::NO_CACHE) {
68 bool isNewEntry =
false;
69 std::tie(it, isNewEntry) = m_table.emplace(data.shared_from_this(), isUnsolicited);
80 m_policy->afterRefresh(it);
83 m_policy->afterInsert(it);
87 std::pair<Cs::const_iterator, Cs::const_iterator>
88 Cs::findPrefixRange(
const Name& prefix)
const 90 auto first = m_table.lower_bound(prefix);
91 auto last = m_table.end();
92 if (prefix.
size() > 0) {
99 Cs::eraseImpl(
const Name& prefix,
size_t limit)
102 std::tie(i, last) = findPrefixRange(prefix);
105 while (i != last && nErased < limit) {
106 m_policy->beforeErase(i);
107 i = m_table.erase(i);
114 Cs::findImpl(
const Interest& interest)
const 116 if (!m_shouldServe || m_policy->getLimit() == 0) {
117 return m_table.end();
121 auto range = findPrefixRange(prefix);
122 auto match = std::find_if(range.first, range.second,
123 [&interest] (
const auto& entry) { return entry.canSatisfy(interest); });
125 if (match == range.second) {
127 return m_table.end();
129 NFD_LOG_DEBUG(
"find " << prefix <<
" matching " << match->getName());
130 m_policy->beforeUse(match);
138 for (
const Entry& entry : m_table) {
146 BOOST_ASSERT(policy !=
nullptr);
147 BOOST_ASSERT(m_policy !=
nullptr);
148 size_t limit = m_policy->getLimit();
150 m_policy->setLimit(limit);
154 Cs::setPolicyImpl(unique_ptr<Policy> policy)
158 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
auto it) { m_table.erase(it); });
160 m_policy->setCs(
this);
161 BOOST_ASSERT(m_policy->getCs() ==
this);
167 if (m_shouldAdmit == shouldAdmit) {
171 NFD_LOG_INFO((shouldAdmit ?
"Enabling" :
"Disabling") <<
" Data admittance");
177 if (m_shouldServe == shouldServe) {
181 NFD_LOG_INFO((shouldServe ?
"Enabling" :
"Disabling") <<
" Data serving");
shared_ptr< T > getTag() const
get a tag item
static unique_ptr< Policy > makeDefaultPolicy()
#define NFD_LOG_INIT(name)
bool isUnsolicited() const
return whether the stored Data is unsolicited
static unique_ptr< Policy > create(const std::string &policyName)
Name getSuccessor() const
Get the successor of a name.
bool shouldAdmit() const
get CS_ENABLE_ADMIT flag
Represents an Interest packet.
bool shouldServe() const
get CS_ENABLE_SERVE flag
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
provides a tag type for simple types
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Copyright (c) 2011-2015 Regents of the University of California.
constexpr const T & get() const noexcept
Table::const_iterator const_iterator
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Cs(size_t nMaxPackets=10)
const Name & getName() const noexcept
Get name.
CachePolicyType
indicates the cache policy applied to a Data packet
Represents an absolute name.
size_t size() const
Returns the number of components.
const Name & getName() const noexcept
void clearUnsolicited()
clear 'unsolicited' flag
Represents a Data packet.
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
void updateFreshUntil()
recalculate when the entry would become non-fresh, relative to current time