table: ContentStore recognizes CachingPolicy-NoCache
refs #2185
Change-Id: Id3dab8936c4dafc96c5d8933d7e75c6cc2e31ff2
diff --git a/daemon/table/cs.cpp b/daemon/table/cs.cpp
index e1e8e73..2226335 100644
--- a/daemon/table/cs.cpp
+++ b/daemon/table/cs.cpp
@@ -63,6 +63,16 @@
{
NFD_LOG_DEBUG("insert " << data.getName());
+ // recognize CachingPolicy
+ using ndn::nfd::LocalControlHeader;
+ const LocalControlHeader& lch = data.getLocalControlHeader();
+ if (lch.hasCachingPolicy()) {
+ LocalControlHeader::CachingPolicy policy = lch.getCachingPolicy();
+ if (policy == LocalControlHeader::CachingPolicy::NO_CACHE) {
+ return false;
+ }
+ }
+
bool isNewEntry = false; TableIt it;
// use .insert because gcc46 does not support .emplace
std::tie(it, isNewEntry) = m_table.insert(EntryImpl(data.shared_from_this(), isUnsolicited));
diff --git a/tests/daemon/table/cs.t.cpp b/tests/daemon/table/cs.t.cpp
index 6d69eda..43c65af 100644
--- a/tests/daemon/table/cs.t.cpp
+++ b/tests/daemon/table/cs.t.cpp
@@ -33,6 +33,7 @@
namespace tests {
using namespace nfd::tests;
+using ndn::nfd::LocalControlHeader;
BOOST_FIXTURE_TEST_SUITE(TableCs, BaseFixture)
@@ -315,6 +316,18 @@
BOOST_AUTO_TEST_SUITE_END()
+BOOST_AUTO_TEST_CASE(CachingPolicyNoCache)
+{
+ Cs cs(3);
+
+ shared_ptr<Data> dataA = makeData("ndn:/A");
+ dataA->getLocalControlHeader().setCachingPolicy(LocalControlHeader::CachingPolicy::NO_CACHE);
+ dataA->wireEncode();
+ BOOST_CHECK_EQUAL(cs.insert(*dataA), false);
+
+ BOOST_CHECK(cs.find(Interest("ndn:/A")) == nullptr);
+}
+
BOOST_FIXTURE_TEST_CASE(Evict, UnitTestTimeFixture)
{
Cs cs(3);