30 #include <ndn-cxx/lp/tags.hpp> 31 #include <ndn-cxx/util/concepts.hpp> 43 const std::string DEFAULT_POLICY =
"priority_fifo";
52 m_policy->setLimit(nMaxPackets);
58 if (!m_shouldAdmit || m_policy->getLimit() == 0) {
67 if (policy == lp::CachePolicyType::NO_CACHE) {
73 bool isNewEntry =
false;
74 std::tie(it, isNewEntry) = m_table.emplace(data.shared_from_this(), isUnsolicited);
85 m_policy->afterRefresh(it);
88 m_policy->afterInsert(it);
95 BOOST_ASSERT(static_cast<bool>(cb));
97 iterator first = m_table.lower_bound(prefix);
99 if (prefix.
size() > 0) {
104 while (first != last && nErased < limit) {
105 m_policy->beforeErase(first);
106 first = m_table.erase(first);
120 BOOST_ASSERT(static_cast<bool>(hitCallback));
121 BOOST_ASSERT(static_cast<bool>(missCallback));
123 if (!m_shouldServe || m_policy->getLimit() == 0) {
124 missCallback(interest);
129 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
131 iterator first = m_table.lower_bound(prefix);
133 if (prefix.
size() > 0) {
139 match = this->findRightmost(interest, first, last);
142 match = this->findLeftmost(interest, first, last);
147 missCallback(interest);
151 m_policy->beforeUse(match);
152 hitCallback(interest, match->getData());
168 size_t interestNameLength = interest.
getName().
size();
169 for (
iterator right = last; right != first;) {
173 if (prev->getName().size() == interestNameLength) {
175 iterator matchExact = this->findRightmostAmongExact(interest, first, right);
176 return matchExact == right ? last : matchExact;
179 Name prefix = prev->getName().getPrefix(interestNameLength + 1);
180 iterator left = m_table.lower_bound(prefix);
184 iterator match = this->findLeftmost(interest, left, right);
185 if (match != right) {
203 for (
const EntryImpl& entry : m_table) {
211 BOOST_ASSERT(policy !=
nullptr);
212 BOOST_ASSERT(m_policy !=
nullptr);
213 size_t limit = m_policy->getLimit();
214 this->setPolicyImpl(std::move(policy));
215 m_policy->setLimit(limit);
219 Cs::setPolicyImpl(unique_ptr<Policy> policy)
222 m_policy = std::move(policy);
223 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
iterator it) {
227 m_policy->setCs(
this);
228 BOOST_ASSERT(m_policy->getCs() ==
this);
std::function< void(size_t nErased)> AfterEraseCallback
shared_ptr< T > getTag() const
get a tag item
const Name & getName() const
Get name.
bool isUnsolicited() const
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
It find_last_if(It first, It last, Pred p)
Represents an Interest packet.
#define NFD_LOG_DEBUG(expression)
bool shouldServe() const
get CS_ENABLE_SERVE flag
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
#define NFD_LOG_INFO(expression)
NDN_CXX_ASSERT_FORWARD_ITERATOR(Cs::const_iterator)
an Entry in ContentStore implementation
provides a tag type for simple types
Table::const_iterator iterator
#define NFD_LOG_TRACE(expression)
void insert(const Data &data, bool isUnsolicited=false)
inserts a Data packet
Copyright (c) 2011-2015 Regents of the University of California.
void erase(const Name &prefix, size_t limit, const AfterEraseCallback &cb)
asynchronously erases entries under prefix
boost::transform_iterator< EntryFromEntryImpl, iterator, const Entry & > const_iterator
ContentStore iterator (public API)
void setPolicy(unique_ptr< Policy > policy)
change replacement policy
Cs(size_t nMaxPackets=10)
unique_ptr< Policy > makeDefaultPolicy()
CachePolicyType
indicates the cache policy applied to a Data packet
Represents an absolute name.
void find(const Interest &interest, const HitCallback &hitCallback, const MissCallback &missCallback) const
finds the best matching Data packet
size_t size() const
Get number of components.
void updateStaleTime()
refreshes stale time relative to current time
NDN_CXX_DEPRECATED int getChildSelector() const
std::function< void(const Interest &, const Data &)> HitCallback
#define NFD_LOG_INIT(name)
Represents a Data packet.
std::function< void(const Interest &)> MissCallback
bool canSatisfy(const Interest &interest) const
determines whether Interest can be satisified by the stored Data
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
const Name & getName() const