40 static unique_ptr<Policy>
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);
74 EntryImpl& entry = const_cast<EntryImpl&>(*it);
84 m_policy->afterRefresh(it);
87 m_policy->afterInsert(it);
94 BOOST_ASSERT(static_cast<bool>(cb));
96 iterator first = m_table.lower_bound(prefix);
98 if (prefix.
size() > 0) {
103 while (first != last && nErased < limit) {
104 m_policy->beforeErase(first);
105 first = m_table.erase(first);
119 BOOST_ASSERT(static_cast<bool>(hitCallback));
120 BOOST_ASSERT(static_cast<bool>(missCallback));
122 if (!m_shouldServe || m_policy->getLimit() == 0) {
123 missCallback(interest);
128 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
130 iterator first = m_table.lower_bound(prefix);
132 if (prefix.
size() > 0) {
138 match = this->findRightmost(interest, first, last);
141 match = this->findLeftmost(interest, first, last);
146 missCallback(interest);
150 m_policy->beforeUse(match);
151 hitCallback(interest, match->getData());
157 return std::find_if(first, last, [&interest] (
const auto& entry) {
return entry.canSatisfy(interest); });
167 size_t interestNameLength = interest.getName().size();
168 for (
iterator right = last; right != first;) {
172 if (prev->getName().size() == interestNameLength) {
174 iterator matchExact = this->findRightmostAmongExact(interest, first, right);
175 return matchExact == right ? last : matchExact;
178 Name prefix = prev->getName().getPrefix(interestNameLength + 1);
179 iterator left = m_table.lower_bound(prefix);
183 iterator match = this->findLeftmost(interest, left, right);
184 if (match != right) {
195 return find_last_if(first, last, [&interest] (
const auto& entry) {
return entry.canSatisfy(interest); });
202 for (
const EntryImpl& entry : m_table) {
210 BOOST_ASSERT(policy !=
nullptr);
211 BOOST_ASSERT(m_policy !=
nullptr);
212 size_t limit = m_policy->getLimit();
213 this->setPolicyImpl(std::move(policy));
214 m_policy->setLimit(limit);
218 Cs::setPolicyImpl(unique_ptr<Policy> policy)
221 m_policy = std::move(policy);
222 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
iterator it) {
226 m_policy->setCs(
this);
227 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.
int getChildSelector() const
static unique_ptr< Policy > makeDefaultPolicy()
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.
bool shouldServe() const
get CS_ENABLE_SERVE flag
void enableAdmit(bool shouldAdmit)
set CS_ENABLE_ADMIT flag
NDN_CXX_ASSERT_FORWARD_ITERATOR(Cs::const_iterator)
an Entry in ContentStore implementation
provides a tag type for simple types
Table::const_iterator iterator
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
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)
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
std::function< void(const Interest &, const Data &)> HitCallback
#define NFD_LOG_INIT(name)
Represents a Data packet.
std::function< void(const Interest &)> MissCallback
void enableServe(bool shouldServe)
set CS_ENABLE_SERVE flag
const Name & getName() const