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();
120 const Name& prefix = interest.getName();
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);