Skip to content

Commit 96a087a

Browse files
authored
Add clear_resolved_cache implementation (#893)
1 parent 69d2c11 commit 96a087a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

boost/network/protocol/http/policies/async_resolver.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {
3636
typedef std::function<void(resolver_type &, string_type, std::uint16_t,
3737
resolve_completion_function)> resolve_function;
3838

39+
void clear_resolved_cache() { clear_cache_.store(true); }
40+
3941
protected:
4042
bool cache_resolved_;
43+
std::atomic<bool> clear_cache_;
4144
endpoint_cache endpoint_cache_;
4245
std::shared_ptr<boost::asio::io_service> service_;
4346
std::shared_ptr<boost::asio::io_service::strand> resolver_strand_;
4447

4548
explicit async_resolver(bool cache_resolved)
46-
: cache_resolved_(cache_resolved), endpoint_cache_() {}
49+
: cache_resolved_(cache_resolved), clear_cache_(false), endpoint_cache_() {}
4750

4851
void resolve(resolver_type &resolver_, string_type const &host,
4952
std::uint16_t port, resolve_completion_function once_resolved) {
50-
if (cache_resolved_) {
53+
if (cache_resolved_ && !clear_cache_.load()) {
5154
typename endpoint_cache::iterator iter =
5255
endpoint_cache_.find(boost::to_lower_copy(host));
5356
if (iter != endpoint_cache_.end()) {
@@ -74,6 +77,9 @@ struct async_resolver : std::enable_shared_from_this<async_resolver<Tag> > {
7477
typename endpoint_cache::iterator iter;
7578
bool inserted = false;
7679
if (!ec && cache_resolved_) {
80+
if (clear_cache_.exchange(false)) {
81+
endpoint_cache_.clear();
82+
}
7783
std::tie(iter, inserted) = endpoint_cache_.insert(std::make_pair(
7884
host, std::make_pair(endpoint_iterator, resolver_iterator())));
7985
once_resolved(ec, iter->second);

boost/network/protocol/http/policies/sync_resolver.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,26 @@ struct sync_resolver {
2727
typedef std::pair<resolver_iterator, resolver_iterator>
2828
resolver_iterator_pair;
2929

30+
void clear_resolved_cache() { clear_cache_.store(true); }
31+
3032
protected:
3133
typedef typename string<Tag>::type string_type;
3234
typedef std::unordered_map<string_type, resolver_iterator_pair>
3335
resolved_cache;
3436
resolved_cache endpoint_cache_;
3537
bool cache_resolved_;
38+
std::atomic<bool> clear_cache_;
3639

37-
explicit sync_resolver(bool cache_resolved) : cache_resolved_(cache_resolved) {}
40+
explicit sync_resolver(bool cache_resolved)
41+
: cache_resolved_(cache_resolved), clear_cache_(false) {}
3842

3943
resolver_iterator_pair resolve(resolver_type& resolver_,
4044
string_type /*unused*/const& hostname,
4145
string_type const& port) {
4246
if (cache_resolved_) {
47+
if (clear_cache_.exchange(false)) {
48+
endpoint_cache_.clear();
49+
}
4350
typename resolved_cache::iterator cached_iterator =
4451
endpoint_cache_.find(hostname);
4552
if (cached_iterator == endpoint_cache_.end()) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy