diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 07:23:40 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-12-10 07:23:40 +0000 |
commit | 112bd4674a886777b79dcd03263088b692fb47fd (patch) | |
tree | 7cf667fa50e6e9284d3a4f1d294cf86719698ff9 /net | |
parent | a4121a67a6a1383048d31130305e472966b44c97 (diff) | |
download | chromium_src-112bd4674a886777b79dcd03263088b692fb47fd.zip chromium_src-112bd4674a886777b79dcd03263088b692fb47fd.tar.gz chromium_src-112bd4674a886777b79dcd03263088b692fb47fd.tar.bz2 |
Cache failed DNS resolutions for 1 second.
This is a very small time to live, since we want to be able to respond quickly when formerly unresolvable names become resolvable.
Even such a small time is still useful, since cache misses for unresolvable names can be extremely costly (order of several seconds).
For example, in our corp PAC script, the URL's host is resolved 3 times, so:
Without caching, total runtime is (2.5 seconds) * 3 --> 7.5 seconds.
Whereas with caching it would be: (2.5 seconds) * 1 --> 2.5 seconds
This time to live will need to be tuned as part of bug 25472.
BUG=11079
Review URL: http://codereview.chromium.org/464084
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34238 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/host_cache.cc | 12 | ||||
-rw-r--r-- | net/base/host_cache.h | 22 | ||||
-rw-r--r-- | net/base/host_cache_unittest.cc | 88 | ||||
-rw-r--r-- | net/base/host_resolver_impl.cc | 30 | ||||
-rw-r--r-- | net/base/host_resolver_impl.h | 23 | ||||
-rw-r--r-- | net/base/host_resolver_impl_unittest.cc | 37 | ||||
-rw-r--r-- | net/base/mock_host_resolver.cc | 12 | ||||
-rw-r--r-- | net/tools/hresolv/hresolv.cc | 7 | ||||
-rw-r--r-- | net/url_request/url_request_view_net_internals_job.cc | 15 |
9 files changed, 174 insertions, 72 deletions
diff --git a/net/base/host_cache.cc b/net/base/host_cache.cc index fbe2a7e..791ecca 100644 --- a/net/base/host_cache.cc +++ b/net/base/host_cache.cc @@ -22,8 +22,12 @@ HostCache::Entry::~Entry() { //----------------------------------------------------------------------------- -HostCache::HostCache(size_t max_entries, size_t cache_duration_ms) - : max_entries_(max_entries), cache_duration_ms_(cache_duration_ms) { +HostCache::HostCache(size_t max_entries, + base::TimeDelta success_entry_ttl, + base::TimeDelta failure_entry_ttl) + : max_entries_(max_entries), + success_entry_ttl_(success_entry_ttl), + failure_entry_ttl_(failure_entry_ttl) { } HostCache::~HostCache() { @@ -53,7 +57,7 @@ HostCache::Entry* HostCache::Set(const Key& key, return NULL; base::TimeTicks expiration = now + - base::TimeDelta::FromMilliseconds(cache_duration_ms_); + (error == OK ? success_entry_ttl_ : failure_entry_ttl_); scoped_refptr<Entry>& entry = entries_[key]; if (!entry) { @@ -77,7 +81,7 @@ HostCache::Entry* HostCache::Set(const Key& key, // static bool HostCache::CanUseEntry(const Entry* entry, const base::TimeTicks now) { - return entry->error == OK && entry->expiration > now; + return entry->expiration > now; } void HostCache::Compact(base::TimeTicks now, const Entry* pinned_entry) { diff --git a/net/base/host_cache.h b/net/base/host_cache.h index c7127b0..4eb5853 100644 --- a/net/base/host_cache.h +++ b/net/base/host_cache.h @@ -57,9 +57,12 @@ class HostCache { typedef std::map<Key, scoped_refptr<Entry> > EntryMap; - // Constructs a HostCache whose entries are valid for |cache_duration_ms| - // milliseconds. The cache will store up to |max_entries|. - HostCache(size_t max_entries, size_t cache_duration_ms); + // Constructs a HostCache that caches successful host resolves for + // |success_entry_ttl| time, and failed host resolves for + // |failure_entry_ttl|. The cache will store up to |max_entries|. + HostCache(size_t max_entries, + base::TimeDelta success_entry_ttl, + base::TimeDelta failure_entry_ttl); ~HostCache(); @@ -90,8 +93,12 @@ class HostCache { return max_entries_; } - size_t cache_duration_ms() const { - return cache_duration_ms_; + base::TimeDelta success_entry_ttl() const { + return success_entry_ttl_; + } + + base::TimeDelta failure_entry_ttl() const { + return failure_entry_ttl_; } // Note that this map may contain expired entries. @@ -113,8 +120,9 @@ class HostCache { // Bound on total size of the cache. size_t max_entries_; - // Time to live for cache entries in milliseconds. - size_t cache_duration_ms_; + // Time to live for cache entries. + base::TimeDelta success_entry_ttl_; + base::TimeDelta failure_entry_ttl_; // Map from hostname (presumably in lowercase canonicalized format) to // a resolved result entry. diff --git a/net/base/host_cache_unittest.cc b/net/base/host_cache_unittest.cc index b51b2e0..5f4e21b 100644 --- a/net/base/host_cache_unittest.cc +++ b/net/base/host_cache_unittest.cc @@ -14,7 +14,9 @@ namespace net { namespace { const int kMaxCacheEntries = 10; -const int kCacheDurationMs = 10000; // 10 seconds. + +const base::TimeDelta kSuccessEntryTTL = base::TimeDelta::FromSeconds(10); +const base::TimeDelta kFailureEntryTTL = base::TimeDelta::FromSeconds(0); // Builds a key for |hostname|, defaulting the address family to unspecified. HostCache::Key Key(const std::string& hostname) { @@ -24,7 +26,7 @@ HostCache::Key Key(const std::string& hostname) { } // namespace TEST(HostCacheTest, Basic) { - HostCache cache(kMaxCacheEntries, kCacheDurationMs); + HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); // Start at t=0. base::TimeTicks now; @@ -81,9 +83,10 @@ TEST(HostCacheTest, Basic) { EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), now) == NULL); } -// Try caching entries for a failed resolve attempt. -TEST(HostCacheTest, NegativeEntry) { - HostCache cache(kMaxCacheEntries, kCacheDurationMs); +// Try caching entries for a failed resolve attempt -- since we set +// the TTL of such entries to 0 it won't work. +TEST(HostCacheTest, NoCacheNegative) { + HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); // Set t=0. base::TimeTicks now; @@ -103,9 +106,70 @@ TEST(HostCacheTest, NegativeEntry) { EXPECT_TRUE(cache.Lookup(Key("foobar.com"), now) == NULL); } +// Try caching entries for a failed resolves for 10 seconds. +TEST(HostCacheTest, CacheNegativeEntry) { + HostCache cache(kMaxCacheEntries, + base::TimeDelta::FromSeconds(0), // success entry TTL. + base::TimeDelta::FromSeconds(10)); // failure entry TTL. + + // Start at t=0. + base::TimeTicks now; + + const HostCache::Entry* entry1 = NULL; // Entry for foobar.com. + const HostCache::Entry* entry2 = NULL; // Entry for foobar2.com. + + EXPECT_EQ(0U, cache.size()); + + // Add an entry for "foobar.com" at t=0. + EXPECT_TRUE(cache.Lookup(Key("foobar.com"), base::TimeTicks()) == NULL); + cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now); + entry1 = cache.Lookup(Key("foobar.com"), base::TimeTicks()); + EXPECT_FALSE(entry1 == NULL); + EXPECT_EQ(1U, cache.size()); + + // Advance to t=5. + now += base::TimeDelta::FromSeconds(5); + + // Add an entry for "foobar2.com" at t=5. + EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), base::TimeTicks()) == NULL); + cache.Set(Key("foobar2.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now); + entry2 = cache.Lookup(Key("foobar2.com"), base::TimeTicks()); + EXPECT_FALSE(NULL == entry1); + EXPECT_EQ(2U, cache.size()); + + // Advance to t=9 + now += base::TimeDelta::FromSeconds(4); + + // Verify that the entries we added are still retrievable, and usable. + EXPECT_EQ(entry1, cache.Lookup(Key("foobar.com"), now)); + EXPECT_EQ(entry2, cache.Lookup(Key("foobar2.com"), now)); + + // Advance to t=10; entry1 is now expired. + now += base::TimeDelta::FromSeconds(1); + + EXPECT_TRUE(cache.Lookup(Key("foobar.com"), now) == NULL); + EXPECT_EQ(entry2, cache.Lookup(Key("foobar2.com"), now)); + + // Update entry1, so it is no longer expired. + cache.Set(Key("foobar.com"), ERR_NAME_NOT_RESOLVED, AddressList(), now); + // Re-uses existing entry storage. + EXPECT_EQ(entry1, cache.Lookup(Key("foobar.com"), now)); + EXPECT_EQ(2U, cache.size()); + + // Both entries should still be retrievable and usable. + EXPECT_EQ(entry1, cache.Lookup(Key("foobar.com"), now)); + EXPECT_EQ(entry2, cache.Lookup(Key("foobar2.com"), now)); + + // Advance to t=20; both entries are now expired. + now += base::TimeDelta::FromSeconds(10); + + EXPECT_TRUE(cache.Lookup(Key("foobar.com"), now) == NULL); + EXPECT_TRUE(cache.Lookup(Key("foobar2.com"), now) == NULL); +} + TEST(HostCacheTest, Compact) { // Initial entries limit is big enough to accomadate everything we add. - HostCache cache(kMaxCacheEntries, kCacheDurationMs); + HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); EXPECT_EQ(0U, cache.size()); @@ -171,16 +235,14 @@ TEST(HostCacheTest, Compact) { // Add entries while the cache is at capacity, causing evictions. TEST(HostCacheTest, SetWithCompact) { - HostCache cache(3, kCacheDurationMs); + HostCache cache(3, kSuccessEntryTTL, kFailureEntryTTL); // t=10 - base::TimeTicks now = - base::TimeTicks() + base::TimeDelta::FromMilliseconds(kCacheDurationMs); + base::TimeTicks now = base::TimeTicks() + kSuccessEntryTTL; cache.Set(Key("host1"), OK, AddressList(), now); cache.Set(Key("host2"), OK, AddressList(), now); - cache.Set(Key("expired"), OK, AddressList(), - now - base::TimeDelta::FromMilliseconds(kCacheDurationMs)); + cache.Set(Key("expired"), OK, AddressList(), now - kSuccessEntryTTL); EXPECT_EQ(3U, cache.size()); @@ -209,7 +271,7 @@ TEST(HostCacheTest, SetWithCompact) { // Tests that the same hostname can be duplicated in the cache, so long as // the address family differs. TEST(HostCacheTest, AddressFamilyIsPartOfKey) { - HostCache cache(kMaxCacheEntries, kCacheDurationMs); + HostCache cache(kMaxCacheEntries, kSuccessEntryTTL, kFailureEntryTTL); // t=0. base::TimeTicks now; @@ -243,7 +305,7 @@ TEST(HostCacheTest, AddressFamilyIsPartOfKey) { TEST(HostCacheTest, NoCache) { // Disable caching. - HostCache cache(0, kCacheDurationMs); + HostCache cache(0, kSuccessEntryTTL, kFailureEntryTTL); EXPECT_TRUE(cache.caching_is_disabled()); // Set t=0. diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index 15ab7e8..193eb0e6 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -35,9 +35,13 @@ namespace net { HostResolver* CreateSystemHostResolver() { static const size_t kMaxHostCacheEntries = 100; - static const size_t kHostCacheExpirationMs = 60000; // 1 minute. - return new HostResolverImpl( - NULL, kMaxHostCacheEntries, kHostCacheExpirationMs); + + HostCache* cache = new HostCache( + kMaxHostCacheEntries, + base::TimeDelta::FromMinutes(1), + base::TimeDelta::FromSeconds(1)); + + return new HostResolverImpl(NULL, cache); } static int ResolveAddrInfo(HostResolverProc* resolver_proc, @@ -287,9 +291,8 @@ class HostResolverImpl::Job //----------------------------------------------------------------------------- HostResolverImpl::HostResolverImpl(HostResolverProc* resolver_proc, - int max_cache_entries, - int cache_duration_ms) - : cache_(max_cache_entries, cache_duration_ms), + HostCache* cache) + : cache_(cache), next_request_id_(0), resolver_proc_(resolver_proc), default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), @@ -333,12 +336,13 @@ int HostResolverImpl::Resolve(const RequestInfo& info, key.address_family = default_address_family_; // If we have an unexpired cache entry, use it. - if (info.allow_cached_response()) { - const HostCache::Entry* cache_entry = cache_.Lookup( + if (info.allow_cached_response() && cache_.get()) { + const HostCache::Entry* cache_entry = cache_->Lookup( key, base::TimeTicks::Now()); if (cache_entry) { - addresses->SetFrom(cache_entry->addrlist, info.port()); int error = cache_entry->error; + if (error == OK) + addresses->SetFrom(cache_entry->addrlist, info.port()); // Update the load log and notify registered observers. OnFinishRequest(load_log, request_id, info, error); @@ -358,7 +362,8 @@ int HostResolverImpl::Resolve(const RequestInfo& info, } // Write to cache. - cache_.Set(key, error, addrlist, base::TimeTicks::Now()); + if (cache_.get()) + cache_->Set(key, error, addrlist, base::TimeTicks::Now()); // Update the load log and notify registered observers. OnFinishRequest(load_log, request_id, info, error); @@ -429,7 +434,7 @@ void HostResolverImpl::RemoveObserver(Observer* observer) { } HostCache* HostResolverImpl::GetHostCache() { - return &cache_; + return cache_.get(); } void HostResolverImpl::Shutdown() { @@ -467,7 +472,8 @@ void HostResolverImpl::OnJobComplete(Job* job, RemoveOutstandingJob(job); // Write result to the cache. - cache_.Set(job->key(), error, addrlist, base::TimeTicks::Now()); + if (cache_.get()) + cache_->Set(job->key(), error, addrlist, base::TimeTicks::Now()); // Make a note that we are executing within OnJobComplete() in case the // HostResolver is deleted by a callback invocation. diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index 9dad6f8..84acdc2 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "base/scoped_ptr.h" #include "net/base/host_cache.h" #include "net/base/host_resolver.h" #include "net/base/host_resolver_proc.h" @@ -41,15 +42,17 @@ namespace net { // class HostResolverImpl : public HostResolver { public: - // Creates a HostResolver that caches up to |max_cache_entries| for - // |cache_duration_ms| milliseconds. |resolver_proc| is used to perform - // the actual resolves; it must be thread-safe since it is run from - // multiple worker threads. If |resolver_proc| is NULL then the default - // host resolver procedure is used (which is SystemHostResolverProc except - // if overridden) - HostResolverImpl(HostResolverProc* resolver_proc, - int max_cache_entries, - int cache_duration_ms); + // Creates a HostResolver that first uses the local cache |cache|, and then + // falls back to |resolver_proc|. + // + // If |cache| is NULL, then no caching is used. Otherwise we take + // ownership of the |cache| pointer, and will free it during destructor. + // + // |resolver_proc| is used to perform the actual resolves; it must be + // thread-safe since it is run from multiple worker threads. If + // |resolver_proc| is NULL then the default host resolver procedure is + // used (which is SystemHostResolverProc except if overridden). + HostResolverImpl(HostResolverProc* resolver_proc, HostCache* cache); // HostResolver methods: virtual int Resolve(const RequestInfo& info, @@ -117,7 +120,7 @@ class HostResolverImpl : public HostResolver { const RequestInfo& info); // Cache of host resolution results. - HostCache cache_; + scoped_ptr<HostCache> cache_; // Map from hostname to outstanding job. JobMap jobs_; diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 1ec38b2..fb7aa05 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -30,8 +30,13 @@ namespace net { namespace { -const int kMaxCacheEntries = 100; -const int kMaxCacheAgeMs = 60000; + +HostCache* CreateDefaultCache() { + return new HostCache( + 100, // max cache entries. + base::TimeDelta::FromMinutes(1), + base::TimeDelta::FromSeconds(0)); +} // A variant of WaitingHostResolverProc that pushes each host mapped into a // list. @@ -186,7 +191,7 @@ TEST_F(HostResolverImplTest, SynchronousLookup) { resolver_proc->AddRule("just.testing", "192.168.1.42"); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); HostResolver::RequestInfo info("just.testing", kPortnum); scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); @@ -218,7 +223,7 @@ TEST_F(HostResolverImplTest, AsynchronousLookup) { resolver_proc->AddRule("just.testing", "192.168.1.42"); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); HostResolver::RequestInfo info("just.testing", kPortnum); scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); @@ -255,7 +260,7 @@ TEST_F(HostResolverImplTest, CanceledAsynchronousLookup) { scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); { scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); AddressList adrlist; const int kPortnum = 80; @@ -290,7 +295,7 @@ TEST_F(HostResolverImplTest, NumericIPv4Address) { resolver_proc->AllowDirectLookup("*"); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); AddressList adrlist; const int kPortnum = 5555; HostResolver::RequestInfo info("127.1.2.3", kPortnum); @@ -315,7 +320,7 @@ TEST_F(HostResolverImplTest, NumericIPv6Address) { // Resolve a plain IPv6 address. Don't worry about [brackets], because // the caller should have removed them. scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); AddressList adrlist; const int kPortnum = 5555; HostResolver::RequestInfo info("2001:db8::1", kPortnum); @@ -350,7 +355,7 @@ TEST_F(HostResolverImplTest, EmptyHost) { resolver_proc->AllowDirectLookup("*"); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); AddressList adrlist; const int kPortnum = 5555; HostResolver::RequestInfo info("", kPortnum); @@ -411,7 +416,7 @@ TEST_F(HostResolverImplTest, DeDupeRequests) { new CapturingHostResolverProc(NULL); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -462,7 +467,7 @@ TEST_F(HostResolverImplTest, CancelMultipleRequests) { new CapturingHostResolverProc(NULL); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -549,7 +554,7 @@ TEST_F(HostResolverImplTest, CancelWithinCallback) { new CapturingHostResolverProc(NULL); scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache())); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -610,7 +615,7 @@ TEST_F(HostResolverImplTest, DeleteWithinCallback) { // checks that the right things happened. Note that the verifier holds the // only reference to |host_resolver|, so it can delete it within callback. HostResolver* host_resolver = - new HostResolverImpl(resolver_proc, kMaxCacheEntries, kMaxCacheAgeMs); + new HostResolverImpl(resolver_proc, CreateDefaultCache()); DeleteWithinCallbackVerifier verifier(host_resolver); // Start 4 requests, duplicating hosts "a". Since the resolver_proc is @@ -663,7 +668,7 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { // Turn off caching for this host resolver. scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, 0, 0)); + new HostResolverImpl(resolver_proc, NULL)); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -728,7 +733,7 @@ class BypassCacheVerifier : public ResolveRequest::Delegate { TEST_F(HostResolverImplTest, BypassCache) { scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(NULL, CreateDefaultCache())); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -812,7 +817,7 @@ class CapturingObserver : public HostResolver::Observer { // synchronous. TEST_F(HostResolverImplTest, Observers) { scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(NULL, CreateDefaultCache())); CapturingObserver observer; @@ -898,7 +903,7 @@ TEST_F(HostResolverImplTest, CancellationObserver) { { // Create a host resolver and attach an observer. scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, kMaxCacheEntries, kMaxCacheAgeMs)); + new HostResolverImpl(NULL, CreateDefaultCache())); host_resolver->AddObserver(&observer); TestCompletionCallback callback; diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index a17ac80..b983724 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -93,10 +93,16 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { proc = interceptor; } - int max_cache_entries = use_caching_ ? 100 : 0; - int max_cache_age_ms = use_caching_ ? 60000 : 0; + HostCache* cache = NULL; - impl_ = new HostResolverImpl(proc, max_cache_entries, max_cache_age_ms); + if (use_caching_) { + cache = new HostCache( + 100, // max entries. + base::TimeDelta::FromMinutes(1), + base::TimeDelta::FromSeconds(0)); + } + + impl_ = new HostResolverImpl(proc, cache); } //----------------------------------------------------------------------------- diff --git a/net/tools/hresolv/hresolv.cc b/net/tools/hresolv/hresolv.cc index 18a98ff..f662817 100644 --- a/net/tools/hresolv/hresolv.cc +++ b/net/tools/hresolv/hresolv.cc @@ -446,8 +446,13 @@ int main(int argc, char** argv) { } } + net::HostCache* cache = new net::HostCache( + options.cache_size, + base::TimeDelta::FromMilliseconds(options.cache_ttl), + base::TimeDelta::FromSeconds(0)); + scoped_refptr<net::HostResolver> host_resolver( - new net::HostResolverImpl(NULL, options.cache_size, options.cache_ttl)); + new net::HostResolverImpl(NULL, cache)); ResolverInvoker invoker(host_resolver.get()); invoker.ResolveAll(hosts_and_times, options.async); diff --git a/net/url_request/url_request_view_net_internals_job.cc b/net/url_request/url_request_view_net_internals_job.cc index e9682dd..d804a88 100644 --- a/net/url_request/url_request_view_net_internals_job.cc +++ b/net/url_request/url_request_view_net_internals_job.cc @@ -217,12 +217,15 @@ class HostResolverCacheSubSection : public SubSection { return; } - out->append(StringPrintf("<ul><li>Size: %" PRIuS "</li>" - "<li>Capacity: %" PRIuS "</li>" - "<li>Time to live (ms): %" PRIuS "</li></ul>", - host_cache->size(), - host_cache->max_entries(), - host_cache->cache_duration_ms())); + out->append(StringPrintf( + "<ul><li>Size: %" PRIuS "</li>" + "<li>Capacity: %" PRIuS "</li>" + "<li>Time to live (ms) for success entries: %" PRId64"</li>" + "<li>Time to live (ms) for failure entries: %" PRId64"</li></ul>", + host_cache->size(), + host_cache->max_entries(), + host_cache->success_entry_ttl().InMilliseconds(), + host_cache->failure_entry_ttl().InMilliseconds())); out->append("<table border=1>" "<tr>" |