1
1
#ifndef RECURSOR_CACHE_HH
2
2
#define RECURSOR_CACHE_HH
19
optString(const string& str)
21
if(str.size() < N-1) {
22
memcpy(buf, str.c_str(), str.size()+1);
23
d_len = str.size() + 1;
31
operator string() const
35
return string(buf, buf + d_len - 1);
38
return *((string*)buf);
44
// cerr<<"did a prune!"<<endl;
46
((string*)buf)->~string();
49
bool operator<(const optString& os) const
51
return (string)*this < (string) os;
56
} __attribute__((packed));
61
class MemRecursorCache // : public RecursorCache
8
#include <boost/utility.hpp>
10
#include <boost/multi_index_container.hpp>
11
#include <boost/multi_index/ordered_index.hpp>
13
#include <boost/multi_index/key_extractors.hpp>
14
#include <boost/version.hpp>
15
#if BOOST_VERSION >= 103300
16
#include <boost/multi_index/hashed_index.hpp>
20
using namespace boost;
21
using namespace ::boost::multi_index;
24
class MemRecursorCache : public boost::noncopyable // : public RecursorCache
65
27
unsigned int size();
66
29
int get(time_t, const string &qname, const QType& qt, set<DNSResourceRecord>* res);
67
30
void replace(const string &qname, const QType& qt, const set<DNSResourceRecord>& content);
68
31
void doPrune(void);
72
35
struct StoredRecord
37
mutable uint32_t d_ttd;
76
41
bool operator<(const StoredRecord& rhs) const
78
return make_pair(d_ttd, d_string) < make_pair(rhs.d_ttd, rhs.d_string);
81
typedef map<string, set<StoredRecord> > cache_t;
43
return d_string < rhs.d_string;
46
unsigned int size() const
48
return 4+d_string.size();
55
predicate(time_t limit) : d_limit(limit)
59
bool operator()(const StoredRecord& sr) const
61
return sr.d_ttd <= d_limit;
66
// typedef __gnu_cxx::hash_map<string, vector<StoredRecord> > cache_t;
70
CacheEntry(const string& name, const vector<StoredRecord>& records) : d_name(name), d_records(records)
73
typedef vector<StoredRecord> records_t;
75
uint32_t getTTD() const
77
uint32_t earliest=numeric_limits<uint32_t>::max();
78
for(records_t::const_iterator i=d_records.begin(); i != d_records.end(); ++i)
79
earliest=min(earliest, i->d_ttd);
85
typedef multi_index_container<
88
#if BOOST_VERSION >= 103300
89
hashed_unique<member<CacheEntry,string,&CacheEntry::d_name> >,
91
ordered_unique<member<CacheEntry,string,&CacheEntry::d_name> >,
93
ordered_non_unique<const_mem_fun<CacheEntry,uint32_t,&CacheEntry::getTTD> >