OLD | NEW |
1 /* | 1 /* |
2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) | 2 Copyright (C) 1998 Lars Knoll (knoll@mpi-hd.mpg.de) |
3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> | 3 Copyright (C) 2001 Dirk Mueller <mueller@kde.org> |
4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 4 Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
5 | 5 |
6 This library is free software; you can redistribute it and/or | 6 This library is free software; you can redistribute it and/or |
7 modify it under the terms of the GNU Library General Public | 7 modify it under the terms of the GNU Library General Public |
8 License as published by the Free Software Foundation; either | 8 License as published by the Free Software Foundation; either |
9 version 2 of the License, or (at your option) any later version. | 9 version 2 of the License, or (at your option) any later version. |
10 | 10 |
11 This library is distributed in the hope that it will be useful, | 11 This library is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 Library General Public License for more details. | 14 Library General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU Library General Public License | 16 You should have received a copy of the GNU Library General Public License |
17 along with this library; see the file COPYING.LIB. If not, write to | 17 along with this library; see the file COPYING.LIB. If not, write to |
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
19 Boston, MA 02110-1301, USA. | 19 Boston, MA 02110-1301, USA. |
20 | 20 |
21 This class provides all functionality needed for loading images, style sheet
s and html | 21 This class provides all functionality needed for loading images, style sheet
s and html |
22 pages from the web. It has a memory cache for these objects. | 22 pages from the web. It has a memory cache for these objects. |
23 */ | 23 */ |
24 | 24 |
25 #ifndef Cache_h | 25 #ifndef Cache_h |
26 #define Cache_h | 26 #define Cache_h |
27 | 27 |
| 28 #include "core/platform/Timer.h" |
28 #include "wtf/HashMap.h" | 29 #include "wtf/HashMap.h" |
29 #include "wtf/Noncopyable.h" | 30 #include "wtf/Noncopyable.h" |
30 #include "wtf/Vector.h" | 31 #include "wtf/Vector.h" |
31 #include "wtf/text/StringHash.h" | 32 #include "wtf/text/StringHash.h" |
32 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
33 | 34 |
34 namespace WebCore { | 35 namespace WebCore { |
35 | 36 |
36 class CachedCSSStyleSheet; | 37 class CachedCSSStyleSheet; |
37 class CachedResource; | 38 class CachedResource; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void remove(CachedResource* resource) { evict(resource); } | 113 void remove(CachedResource* resource) { evict(resource); } |
113 | 114 |
114 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); | 115 static KURL removeFragmentIdentifierIfNeeded(const KURL& originalURL); |
115 | 116 |
116 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, | 117 // Sets the cache's memory capacities, in bytes. These will hold only approx
imately, |
117 // since the decoded cost of resources like scripts and stylesheets is not k
nown. | 118 // since the decoded cost of resources like scripts and stylesheets is not k
nown. |
118 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. | 119 // - minDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is under pressure. |
119 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. | 120 // - maxDeadBytes: The maximum number of bytes that dead resources should c
onsume when the cache is not under pressure. |
120 // - totalBytes: The maximum number of bytes that the cache should consume
overall. | 121 // - totalBytes: The maximum number of bytes that the cache should consume
overall. |
121 void setCapacities(unsigned minDeadBytes, unsigned maxDeadBytes, unsigned to
talBytes); | 122 void setCapacities(unsigned minDeadBytes, unsigned maxDeadBytes, unsigned to
talBytes); |
| 123 void setDelayBeforeLiveDecodedPrune(unsigned seconds) { m_delayBeforeLiveDec
odedPrune = seconds; } |
122 | 124 |
123 void evictResources(); | 125 void evictResources(); |
124 | 126 |
125 void prune(); | 127 void prune(); |
126 void pruneToPercentage(float targetPercentLive); | 128 void pruneToPercentage(float targetPercentLive); |
127 | 129 |
128 void setDeadDecodedDataDeletionInterval(double interval) { m_deadDecodedData
DeletionInterval = interval; } | 130 void setDeadDecodedDataDeletionInterval(double interval) { m_deadDecodedData
DeletionInterval = interval; } |
129 double deadDecodedDataDeletionInterval() const { return m_deadDecodedDataDel
etionInterval; } | 131 double deadDecodedDataDeletionInterval() const { return m_deadDecodedDataDel
etionInterval; } |
130 | 132 |
131 // Calls to put the cached resource into and out of LRU lists. | 133 // Calls to put the cached resource into and out of LRU lists. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 void evict(CachedResource*); | 179 void evict(CachedResource*); |
178 | 180 |
179 static void removeURLFromCacheInternal(ScriptExecutionContext*, const KURL&)
; | 181 static void removeURLFromCacheInternal(ScriptExecutionContext*, const KURL&)
; |
180 | 182 |
181 bool m_inPruneResources; | 183 bool m_inPruneResources; |
182 | 184 |
183 unsigned m_capacity; | 185 unsigned m_capacity; |
184 unsigned m_minDeadCapacity; | 186 unsigned m_minDeadCapacity; |
185 unsigned m_maxDeadCapacity; | 187 unsigned m_maxDeadCapacity; |
186 double m_deadDecodedDataDeletionInterval; | 188 double m_deadDecodedDataDeletionInterval; |
| 189 unsigned m_delayBeforeLiveDecodedPrune; |
187 | 190 |
188 unsigned m_liveSize; // The number of bytes currently consumed by "live" res
ources in the cache. | 191 unsigned m_liveSize; // The number of bytes currently consumed by "live" res
ources in the cache. |
189 unsigned m_deadSize; // The number of bytes currently consumed by "dead" res
ources in the cache. | 192 unsigned m_deadSize; // The number of bytes currently consumed by "dead" res
ources in the cache. |
190 | 193 |
191 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold | 194 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold |
192 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are | 195 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are |
193 // waiting to die when the clients referencing them go away. | 196 // waiting to die when the clients referencing them go away. |
194 Vector<LRUList, 32> m_allResources; | 197 Vector<LRUList, 32> m_allResources; |
195 | 198 |
196 // List just for live resources with decoded data. Access to this list is b
ased off of painting the resource. | 199 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. |
197 LRUList m_liveDecodedResources; | 200 // The lists are ordered by decode priority, with higher indices having high
er priorities. |
| 201 LRUList m_liveDecodedResources[3]; |
198 | 202 |
199 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being | 203 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being |
200 // referenced by a Web page). | 204 // referenced by a Web page). |
201 HashMap<String, CachedResource*> m_resources; | 205 HashMap<String, CachedResource*> m_resources; |
202 | 206 |
203 #ifdef MEMORY_CACHE_STATS | 207 #ifdef MEMORY_CACHE_STATS |
204 Timer<MemoryCache> m_statsTimer; | 208 Timer<MemoryCache> m_statsTimer; |
205 #endif | 209 #endif |
206 }; | 210 }; |
207 | 211 |
208 // Returns the global cache. | 212 // Returns the global cache. |
209 MemoryCache* memoryCache(); | 213 MemoryCache* memoryCache(); |
210 | 214 |
211 // Sets the global cache, used to swap in a test instance. | 215 // Sets the global cache, used to swap in a test instance. |
212 void setMemoryCacheForTesting(MemoryCache*); | 216 void setMemoryCacheForTesting(MemoryCache*); |
213 | 217 |
214 } | 218 } |
215 | 219 |
216 #endif | 220 #endif |
OLD | NEW |