29 #include <ndn-cxx/lp/tags.hpp> 37 BOOST_CONCEPT_ASSERT((boost::ForwardIterator<Cs::const_iterator>));
40 #ifdef HAVE_IS_DEFAULT_CONSTRUCTIBLE 41 static_assert(std::is_default_constructible<Cs::const_iterator>::value,
42 "Cs::const_iterator must be default-constructible");
44 BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<Cs::const_iterator>));
45 #endif // HAVE_IS_DEFAULT_CONSTRUCTIBLE 50 const std::string DEFAULT_POLICY =
"priority_fifo";
54 Cs::Cs(
size_t nMaxPackets, unique_ptr<Policy> policy)
56 this->setPolicyImpl(std::move(policy));
57 m_policy->setLimit(nMaxPackets);
63 m_policy->setLimit(nMaxPackets);
69 return m_policy->getLimit();
75 BOOST_ASSERT(policy !=
nullptr);
76 BOOST_ASSERT(m_policy !=
nullptr);
77 size_t limit = m_policy->getLimit();
78 this->setPolicyImpl(std::move(policy));
79 m_policy->setLimit(limit);
87 if (m_policy->getLimit() == 0) {
96 if (policy == lp::CachePolicyType::NO_CACHE) {
101 bool isNewEntry =
false;
104 std::tie(it, isNewEntry) = m_table.insert(
EntryImpl(data.shared_from_this(), isUnsolicited));
115 m_policy->afterRefresh(it);
118 m_policy->afterInsert(it);
127 BOOST_ASSERT(static_cast<bool>(hitCallback));
128 BOOST_ASSERT(static_cast<bool>(missCallback));
132 NFD_LOG_DEBUG(
"find " << prefix << (isRightmost ?
" R" :
" L"));
134 iterator first = m_table.lower_bound(prefix);
136 if (prefix.
size() > 0) {
142 match = this->findRightmost(interest, first, last);
145 match = this->findLeftmost(interest, first, last);
150 missCallback(interest);
154 m_policy->beforeUse(match);
155 hitCallback(interest, match->getData());
171 size_t interestNameLength = interest.
getName().
size();
172 for (
iterator right = last; right != first;) {
176 if (prev->getName().size() == interestNameLength) {
178 iterator matchExact = this->findRightmostAmongExact(interest, first, right);
179 return matchExact == right ? last : matchExact;
182 Name prefix = prev->getName().
getPrefix(interestNameLength + 1);
183 iterator left = m_table.lower_bound(prefix);
187 iterator match = this->findLeftmost(interest, left, right);
188 if (match != right) {
203 Cs::setPolicyImpl(unique_ptr<Policy> policy)
206 m_policy = std::move(policy);
207 m_beforeEvictConnection = m_policy->beforeEvict.connect([
this] (
iterator it) {
211 m_policy->setCs(
this);
212 BOOST_ASSERT(m_policy->getCs() ==
this);
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
shared_ptr< T > getTag() const
get a tag item
int getChildSelector() const
bool isUnsolicited() const
Cs(size_t nMaxPackets=10, unique_ptr< Policy > policy=makeDefaultPolicy())
Copyright (c) 2014-2016, Regents of the University of California, Arizona Board of Regents...
const Name & getName() const
Get name of the Data packet.
Name getSuccessor() const
Get the successor of a name.
It find_last_if(It first, It last, Pred p)
represents an Interest packet
#define NFD_LOG_DEBUG(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.
unique_ptr< Policy > makeDefaultPolicy()
void setPolicy(unique_ptr< Policy > policy)
changes cs replacement policy
void setLimit(size_t nMaxPackets)
changes capacity (in number of packets)
static unique_ptr< Policy > create(const std::string &key)
CachePolicyType
indicates the cache policy applied to a Data packet
Name abstraction to represent 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
size_t size() const
Get the number of components.
void updateStaleTime()
refreshes stale time relative to current time
#define NFD_LOG_INIT(name)
bool canSatisfy(const Interest &interest) const
determines whether Interest can be satisified by the stored Data
const Name & getName() const