Merge pull request #11737 from kwonoj/feat-cache-capacity

feat(webframe): export set cache capacity interface
This commit is contained in:
Samuel Attard 2018-02-13 06:02:25 +11:00 committed by GitHub
commit 181169b743
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View file

@ -368,6 +368,15 @@ void WebFrame::ClearCache(v8::Isolate* isolate) {
base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL);
}
void WebFrame::SetCacheCapacity(v8::Isolate* isolate, int capacity) {
if (capacity > 0) {
blink::WebCache::SetCapacity(capacity);
} else {
isolate->ThrowException(v8::Exception::TypeError(
mate::StringToV8(isolate, "Invalid cache capacity")));
}
}
// static
void WebFrame::BuildPrototype(
v8::Isolate* isolate, v8::Local<v8::FunctionTemplate> prototype) {
@ -408,6 +417,7 @@ void WebFrame::BuildPrototype(
&WebFrame::SetIsolatedWorldHumanReadableName)
.SetMethod("getResourceUsage", &WebFrame::GetResourceUsage)
.SetMethod("clearCache", &WebFrame::ClearCache)
.SetMethod("setCacheCapacity", &WebFrame::SetCacheCapacity)
// TODO(kevinsawicki): Remove in 2.0, deprecate before then with warnings
.SetMethod("setZoomLevelLimits", &WebFrame::SetVisualZoomLevelLimits);
}

View file

@ -92,6 +92,7 @@ class WebFrame : public mate::Wrappable<WebFrame> {
// Resource related methods
blink::WebCache::ResourceTypeStats GetResourceUsage(v8::Isolate* isolate);
void ClearCache(v8::Isolate* isolate);
void SetCacheCapacity(v8::Isolate* isolate, int capacity);
std::unique_ptr<SpellCheckClient> spell_check_client_;

View file

@ -221,4 +221,13 @@ in your app has occurred 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,
and intend to stay there).
### `webFrame.setCacheCapacity(capacity)`
* `capacity` Integer
Attemp to set the capacity of resource cache for the renderer process in bytes
Note if current cached resource size is larger than newly specified capacity, Electron
will schedule to prune cached resources until it reaches below new capacity.
[spellchecker]: https://github.com/atom/node-spellchecker

View file

@ -139,4 +139,10 @@ describe('webFrame module', function () {
webFrame.setLayoutZoomLevelLimits(0, 25)
})
})
it('supports setting cache capacity', function () {
assert.doesNotThrow(function () {
webFrame.setCacheCapacity(1024)
})
})
})