30 #include <ndn-cxx/lp/tags.hpp> 42 const std::string DEFAULT_POLICY =
"priority_fifo";
51 m_policy->setLimit(nMaxPackets);
57 if (!m_shouldAdmit || m_policy->getLimit() == 0) {
66 if (policy == lp::CachePolicyType::NO_CACHE) {
72 bool isNewEntry =
false;
73 std::tie(it, isNewEntry) = m_table.emplace(data.shared_from_this(), isUnsolicited);
84 m_policy->afterRefresh(it);
87 m_policy->afterInsert(it);
96 BOOST_ASSERT(static_cast<bool>(hitCallback));
97 BOOST_ASSERT(static_cast<bool>(missCallback));
99 if (!m_shouldServe || m_policy->getLimit() == 0) {
100 missCallback(interest);
105 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
107 iterator first = m_table.lower_bound(prefix);
109 if (prefix.
size() > 0) {
115 match = this->findRightmost(interest, first, last);
118 match = this->findLeftmost(interest, first, last);
123 missCallback(interest);
127 m_policy->beforeUse(match);
128 hitCallback(interest, match->getData());
144 size_t interestNameLength = interest.
getName().
size();
145 for (
iterator right = last; right != first;) {
149 if (prev->getName().size() == interestNameLength) {
151 iterator matchExact = this->findRightmostAmongExact(interest, first, right);
152 return matchExact == right ? last : matchExact;
155 Name prefix = prev->getName().getPrefix(interestNameLength + 1);
156 iterator left = m_table.lower_bound(prefix);
160 iterator match = this->findLeftmost(interest, left, right);
161 if (match != right) {
179 for (
const EntryImpl& entry : m_table) {
187 BOOST_ASSERT(policy !=
nullptr);
188 BOOST_ASSERT(m_policy !=
nullptr);
189 size_t limit = m_policy->getLimit();
190 this->setPolicyImpl(std::move(policy));
191 m_policy->setLimit(limit);
195 Cs::setPolicyImpl(unique_ptr<Policy> policy)
198 m_policy = std::move(policy);
199 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
iterator it) {
203 m_policy->setCs(
this);
204 BOOST_ASSERT(m_policy->getCs() ==
this);
shared_ptr< T > getTag() const
get a tag item
const Name & getName() const
Get name.
int getChildSelector() const
bool isUnsolicited() const
implements the ContentStore
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)
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.
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
std::function< void(const Interest &, const Data &data)> HitCallback
std::function< void(const Interest &)> MissCallback
NFD_ASSERT_FORWARD_ITERATOR(Cs::const_iterator)
size_t size() const
Get number of components.
void updateStaleTime()
refreshes stale time relative to current time
#define NFD_LOG_INIT(name)
Represents a Data packet.
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