Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(891)

Side by Side Diff: net/base/host_cache.h

Issue 464084: Cache failed DNS resolutions for 1 second.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Merge changes (to include API change in another file) Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/base/host_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_BASE_HOST_CACHE_H_ 5 #ifndef NET_BASE_HOST_CACHE_H_
6 #define NET_BASE_HOST_CACHE_H_ 6 #define NET_BASE_HOST_CACHE_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 return hostname < other.hostname; 50 return hostname < other.hostname;
51 return address_family < other.address_family; 51 return address_family < other.address_family;
52 } 52 }
53 53
54 std::string hostname; 54 std::string hostname;
55 AddressFamily address_family; 55 AddressFamily address_family;
56 }; 56 };
57 57
58 typedef std::map<Key, scoped_refptr<Entry> > EntryMap; 58 typedef std::map<Key, scoped_refptr<Entry> > EntryMap;
59 59
60 // Constructs a HostCache whose entries are valid for |cache_duration_ms| 60 // Constructs a HostCache that caches successful host resolves for
61 // milliseconds. The cache will store up to |max_entries|. 61 // |success_entry_ttl| time, and failed host resolves for
62 HostCache(size_t max_entries, size_t cache_duration_ms); 62 // |failure_entry_ttl|. The cache will store up to |max_entries|.
63 HostCache(size_t max_entries,
64 base::TimeDelta success_entry_ttl,
65 base::TimeDelta failure_entry_ttl);
63 66
64 ~HostCache(); 67 ~HostCache();
65 68
66 // Returns a pointer to the entry for |key|, which is valid at time 69 // Returns a pointer to the entry for |key|, which is valid at time
67 // |now|. If there is no such entry, returns NULL. 70 // |now|. If there is no such entry, returns NULL.
68 const Entry* Lookup(const Key& key, base::TimeTicks now) const; 71 const Entry* Lookup(const Key& key, base::TimeTicks now) const;
69 72
70 // Overwrites or creates an entry for |key|. Returns the pointer to the 73 // Overwrites or creates an entry for |key|. Returns the pointer to the
71 // entry, or NULL on failure (fails if caching is disabled). 74 // entry, or NULL on failure (fails if caching is disabled).
72 // (|error|, |addrlist|) is the value to set, and |now| is the current 75 // (|error|, |addrlist|) is the value to set, and |now| is the current
(...skipping 10 matching lines...) Expand all
83 86
84 // Returns the number of entries in the cache. 87 // Returns the number of entries in the cache.
85 size_t size() const { 88 size_t size() const {
86 return entries_.size(); 89 return entries_.size();
87 } 90 }
88 91
89 size_t max_entries() const { 92 size_t max_entries() const {
90 return max_entries_; 93 return max_entries_;
91 } 94 }
92 95
93 size_t cache_duration_ms() const { 96 base::TimeDelta success_entry_ttl() const {
94 return cache_duration_ms_; 97 return success_entry_ttl_;
98 }
99
100 base::TimeDelta failure_entry_ttl() const {
101 return failure_entry_ttl_;
95 } 102 }
96 103
97 // Note that this map may contain expired entries. 104 // Note that this map may contain expired entries.
98 const EntryMap& entries() const { 105 const EntryMap& entries() const {
99 return entries_; 106 return entries_;
100 } 107 }
101 108
102 private: 109 private:
103 FRIEND_TEST(HostCacheTest, Compact); 110 FRIEND_TEST(HostCacheTest, Compact);
104 FRIEND_TEST(HostCacheTest, NoCache); 111 FRIEND_TEST(HostCacheTest, NoCache);
105 112
106 // Returns true if this cache entry's result is valid at time |now|. 113 // Returns true if this cache entry's result is valid at time |now|.
107 static bool CanUseEntry(const Entry* entry, const base::TimeTicks now); 114 static bool CanUseEntry(const Entry* entry, const base::TimeTicks now);
108 115
109 // Prunes entries from the cache to bring it below max entry bound. Entries 116 // Prunes entries from the cache to bring it below max entry bound. Entries
110 // matching |pinned_entry| will NOT be pruned. 117 // matching |pinned_entry| will NOT be pruned.
111 void Compact(base::TimeTicks now, const Entry* pinned_entry); 118 void Compact(base::TimeTicks now, const Entry* pinned_entry);
112 119
113 // Bound on total size of the cache. 120 // Bound on total size of the cache.
114 size_t max_entries_; 121 size_t max_entries_;
115 122
116 // Time to live for cache entries in milliseconds. 123 // Time to live for cache entries.
117 size_t cache_duration_ms_; 124 base::TimeDelta success_entry_ttl_;
125 base::TimeDelta failure_entry_ttl_;
118 126
119 // Map from hostname (presumably in lowercase canonicalized format) to 127 // Map from hostname (presumably in lowercase canonicalized format) to
120 // a resolved result entry. 128 // a resolved result entry.
121 EntryMap entries_; 129 EntryMap entries_;
122 130
123 DISALLOW_COPY_AND_ASSIGN(HostCache); 131 DISALLOW_COPY_AND_ASSIGN(HostCache);
124 }; 132 };
125 133
126 } // namespace net 134 } // namespace net
127 135
128 #endif // NET_BASE_HOST_CACHE_H_ 136 #endif // NET_BASE_HOST_CACHE_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/host_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698