S.inc("deferred-cache-inserts");
}
-/** purges entries from the packetcache. If match ends on a $, it is treated as a suffix
- for historical reasons, the first entry in matches is the original command passed to
- pdns_control (typically 'PURGE') and needs to be ignored
-*/
-int PacketCache::purge(const vector<string> &matches)
+/* clears the entire packetcache. */
+int PacketCache::purge()
+{
+ WriteLock l(&d_mut);
+ int delcount=d_map.size();
+ d_map.clear();
+ *d_statnumentries=0;
+ return delcount;
+}
+
+/* purges entries from the packetcache. If match ends on a $, it is treated as a suffix */
+int PacketCache::purge(const string &match)
{
WriteLock l(&d_mut);
int delcount=0;
-
- if(matches.empty()) {
- delcount = d_map.size();
- d_map.clear();
- *d_statnumentries=0;
- return delcount;
- }
/* ok, the suffix delete plan. We want to be able to delete everything that
pertains 'www.powerdns.com' but we also want to be able to delete everything
'www.userpowerdns.com'
*/
- // skip first entry which is the pdns_control command
- for(vector<string>::const_iterator match = ++matches.begin(); match != matches.end() ; ++match) {
- if(ends_with(*match, "$")) {
- string suffix(*match);
- suffix.resize(suffix.size()-1);
-
- cmap_t::const_iterator iter = d_map.lower_bound(tie(suffix));
- cmap_t::const_iterator start=iter;
- string dotsuffix = "."+suffix;
-
- for(; iter != d_map.end(); ++iter) {
- if(!pdns_iequals(iter->qname, suffix) && !iends_with(iter->qname, dotsuffix)) {
- // cerr<<"Stopping!"<<endl;
- break;
- }
- delcount++;
+ if(ends_with(match, "$")) {
+ string suffix(match);
+ suffix.resize(suffix.size()-1);
+
+ cmap_t::const_iterator iter = d_map.lower_bound(tie(suffix));
+ cmap_t::const_iterator start=iter;
+ string dotsuffix = "."+suffix;
+
+ for(; iter != d_map.end(); ++iter) {
+ if(!pdns_iequals(iter->qname, suffix) && !iends_with(iter->qname, dotsuffix)) {
+ // cerr<<"Stopping!"<<endl;
+ break;
}
- d_map.erase(start, iter);
- }
- else {
- delcount=d_map.count(tie(*match));
- pair<cmap_t::iterator, cmap_t::iterator> range = d_map.equal_range(tie(*match));
- d_map.erase(range.first, range.second);
+ delcount++;
}
+ d_map.erase(start, iter);
+ }
+ else {
+ delcount=d_map.count(tie(match));
+ pair<cmap_t::iterator, cmap_t::iterator> range = d_map.equal_range(tie(match));
+ d_map.erase(range.first, range.second);
}
*d_statnumentries=d_map.size();
return delcount;