/*!
* Returns the amount of entries in the cache
+ *
+ * \param qname The name of the entries to be counted
*/
uint64_t NegCache::count(const DNSName& qname) const {
return d_negcache.count(tie(qname));
}
+/*!
+ * Returns the amount of entries in the cache for qname+qtype
+ *
+ * \param qname The name of the entries to be counted
+ * \param qtype The type of the entries to be counted
+ */
+uint64_t NegCache::count(const DNSName& qname, const QType qtype) const {
+ return d_negcache.count(tie(qname, qtype));
+}
+
/*!
* Remove all entries for name from the cache. If subtree is true, wipe all names
* underneath it.
bool get(const DNSName& qname, const QType& qtype, const struct timeval& now, NegCacheEntry& ne);
bool getRootNXTrust(const DNSName& qname, const struct timeval& now, NegCacheEntry& ne);
uint64_t count(const DNSName& qname) const;
+ uint64_t count(const DNSName& qname, const QType qtype) const;
void prune(unsigned int maxEntries);
void clear();
uint64_t dumpToFile(FILE* fd);
fclose(fp);
}
+BOOST_AUTO_TEST_CASE(test_count) {
+ string qname(".powerdns.com");
+ string qname2("powerdns.org");
+ DNSName auth("powerdns.com");
+
+ struct timeval now;
+ Utility::gettimeofday(&now, 0);
+
+ NegCache cache;
+ NegCache::NegCacheEntry ne;
+ ne = genNegCacheEntry(auth, auth, now);
+ cache.add(ne);
+
+ for(int i = 0; i < 400; i++) {
+ ne = genNegCacheEntry(DNSName(std::to_string(i) + qname), auth, now);
+ cache.add(ne);
+ ne = genNegCacheEntry(DNSName(std::to_string(i) + qname2), auth, now);
+ cache.add(ne);
+ }
+
+ uint64_t count;
+ count = cache.count(auth);
+ BOOST_CHECK_EQUAL(count, 1);
+ count = cache.count(auth, QType(1));
+ BOOST_CHECK_EQUAL(count, 0);
+}
+
BOOST_AUTO_TEST_SUITE_END()