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/loader/cache/Resource.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 Resource; | 38 class Resource; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 void remove(Resource* resource) { evict(resource); } | 113 void remove(Resource* 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 | 128 |
127 // Calls to put the cached resource into and out of LRU lists. | 129 // Calls to put the cached resource into and out of LRU lists. |
128 void insertInLRUList(Resource*); | 130 void insertInLRUList(Resource*); |
129 void removeFromLRUList(Resource*); | 131 void removeFromLRUList(Resource*); |
130 | 132 |
131 // Called to adjust the cache totals when a resource changes size. | 133 // Called to adjust the cache totals when a resource changes size. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 168 |
167 void evict(Resource*); | 169 void evict(Resource*); |
168 | 170 |
169 static void removeURLFromCacheInternal(ScriptExecutionContext*, const KURL&)
; | 171 static void removeURLFromCacheInternal(ScriptExecutionContext*, const KURL&)
; |
170 | 172 |
171 bool m_inPruneResources; | 173 bool m_inPruneResources; |
172 | 174 |
173 unsigned m_capacity; | 175 unsigned m_capacity; |
174 unsigned m_minDeadCapacity; | 176 unsigned m_minDeadCapacity; |
175 unsigned m_maxDeadCapacity; | 177 unsigned m_maxDeadCapacity; |
| 178 unsigned m_delayBeforeLiveDecodedPrune; |
| 179 double m_deadDecodedDataDeletionInterval; |
176 | 180 |
177 unsigned m_liveSize; // The number of bytes currently consumed by "live" res
ources in the cache. | 181 unsigned m_liveSize; // The number of bytes currently consumed by "live" res
ources in the cache. |
178 unsigned m_deadSize; // The number of bytes currently consumed by "dead" res
ources in the cache. | 182 unsigned m_deadSize; // The number of bytes currently consumed by "dead" res
ources in the cache. |
179 | 183 |
180 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold | 184 // Size-adjusted and popularity-aware LRU list collection for cache objects.
This collection can hold |
181 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are | 185 // more resources than the cached resource map, since it can also hold "stal
e" multiple versions of objects that are |
182 // waiting to die when the clients referencing them go away. | 186 // waiting to die when the clients referencing them go away. |
183 Vector<LRUList, 32> m_allResources; | 187 Vector<LRUList, 32> m_allResources; |
184 | 188 |
185 // List just for live resources with decoded data. Access to this list is b
ased off of painting the resource. | 189 // Lists just for live resources with decoded data. Access to this list is b
ased off of painting the resource. |
186 LRUList m_liveDecodedResources; | 190 // The lists are ordered by decode priority, with higher indices having high
er priorities. |
| 191 LRUList m_liveDecodedResources[Resource::CacheLiveResourcePriorityHigh + 1]; |
187 | 192 |
188 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being | 193 // A URL-based map of all resources that are in the cache (including the fre
shest version of objects that are currently being |
189 // referenced by a Web page). | 194 // referenced by a Web page). |
190 HashMap<String, Resource*> m_resources; | 195 HashMap<String, Resource*> m_resources; |
191 | 196 |
192 #ifdef MEMORY_CACHE_STATS | 197 #ifdef MEMORY_CACHE_STATS |
193 Timer<MemoryCache> m_statsTimer; | 198 Timer<MemoryCache> m_statsTimer; |
194 #endif | 199 #endif |
195 }; | 200 }; |
196 | 201 |
197 // Returns the global cache. | 202 // Returns the global cache. |
198 MemoryCache* memoryCache(); | 203 MemoryCache* memoryCache(); |
199 | 204 |
200 // Sets the global cache, used to swap in a test instance. | 205 // Sets the global cache, used to swap in a test instance. |
201 void setMemoryCacheForTesting(MemoryCache*); | 206 void setMemoryCacheForTesting(MemoryCache*); |
202 | 207 |
203 } | 208 } |
204 | 209 |
205 #endif | 210 #endif |
OLD | NEW |