Rename webFrame.purgeCaches to webFrame.clearCache

This matches the name of session.clearCache.
This commit is contained in:
Cheng Zhao 2016-05-14 22:48:25 +09:00
parent 7459581d13
commit c740438032
3 changed files with 27 additions and 34 deletions

View file

@ -178,10 +178,9 @@ blink::WebCache::ResourceTypeStats WebFrame::GetResourceUsage(
return stats; return stats;
} }
void WebFrame::PurgeCaches(v8::Isolate* isolate) { void WebFrame::ClearCache(v8::Isolate* isolate) {
isolate->IdleNotificationDeadline(0.5); isolate->IdleNotificationDeadline(0.5);
blink::WebCache::clear(); blink::WebCache::clear();
base::MemoryPressureListener::NotifyMemoryPressure( base::MemoryPressureListener::NotifyMemoryPressure(
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
} }
@ -211,7 +210,7 @@ void WebFrame::BuildPrototype(
.SetMethod("insertText", &WebFrame::InsertText) .SetMethod("insertText", &WebFrame::InsertText)
.SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript) .SetMethod("executeJavaScript", &WebFrame::ExecuteJavaScript)
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage) .SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
.SetMethod("purgeCaches", &WebFrame::PurgeCaches); .SetMethod("clearCache", &WebFrame::ClearCache);
} }
} // namespace api } // namespace api

View file

@ -72,7 +72,7 @@ class WebFrame : public mate::Wrappable<WebFrame> {
// Resource related methods // Resource related methods
blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate); blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate);
void PurgeCaches(v8::Isolate* isolate); void ClearCache(v8::Isolate* isolate);
scoped_ptr<SpellCheckClient> spell_check_client_; scoped_ptr<SpellCheckClient> spell_check_client_;

View file

@ -108,47 +108,41 @@ this limitation.
### `webFrame.getResourceUsage()` ### `webFrame.getResourceUsage()`
Returns more detailed memory usage information in kilobytes of Blink's internal Returns an object describing usage information of Blink's internal memory
memory caches. Returns an Object of the following shape: caches.
```js ```javascript
console.log(webFrame.getResourceUsage())
```
This will generate:
```javascript
{ {
"images": { images: {
"count": 22, count: 22,
"size": 2549, // 2549kb size: 2549,
"liveSize": 2542, // 2542kb, etc... liveSize: 2542,
"decodedSize": 478, decodedSize: 478,
"purgedSize": 0, purgedSize: 0,
"purgeableSize": 0 purgeableSize: 0
}, },
"cssStyleSheets": { cssStyleSheets: { /* same with "images" */ },
"count": 7, xslStyleSheets: { /* same with "images" */ },
/* ... */ fonts: { /* same with "images" */ },
}, other: { /* same with "images" */ },
"xslStyleSheets": {
"count": 0,
/* ... */
},
"fonts": {
"count": 18,
/* ... */
},
"other": {
"count": 0,
/* ... */
}
} }
``` ```
### `webFrame.purgeCaches()` ### `webFrame.clearCache()`
Attempts to free memory that is no longer being used (i.e. images from a Attempts to free memory that is no longer being used (like images from a
previous navigation, etc etc). previous navigation).
Note that blindly calling this method probably makes Electron slower since it Note that blindly calling this method probably makes Electron slower since it
will have to refill these emptied caches, you should only call it if an event will have to refill these emptied caches, you should only call it if an event
in your app has occured that makes you think your page is actually using less in your app has occured that makes you think your page is actually using less
memory (i.e. you have navigated from a super heavy page to a mostly empty one, memory (i.e. you have navigated from a super heavy page to a mostly empty one,
and intend to stay there) and intend to stay there).
[spellchecker]: https://github.com/atom/node-spellchecker [spellchecker]: https://github.com/atom/node-spellchecker