我可以在Chrome中增加QUOTA_BYTES_PER_ITEM吗? [英] Can I increase QUOTA_BYTES_PER_ITEM in Chrome?
问题描述
有没有办法增加chrome.storage.sync.QUOTA_BYTES_PER_ITEM?
对我来说,默认的4096字节有点短。
我试图执行
chrome.storage.sync.QUOTA_BYTES_PER_ITEM = 8192;
然而,似乎实际的限制并没有改变。
我该怎么做?
不, QUOTA_BYTES_PER_ITEM
仅供参考;这不是一个可设定的价值。不过,您可以使用 QUOTA_BYTES_PER_ITEM
的值将项目分成多个项目:
function syncStore(key,objectToStore,callback){
var jsonstr = JSON.stringify(objectToStore);
var i = 0;
var storageObj = {};
//将jsonstr分割成块,并将它们存储在由`key_i`索引的对象中
while(jsonstr.length> 0){
var index = key +_ + i ++;
//由于密钥使用了一些每个商品的配额,请查看剩余的价值
//还修剪掉2用于存储时间`stringify`添加的报价
var valueLength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - index.length - 2;
//修剪细分,因此即使在存储时再次运行JSON.stringify,它也会足够小
var segment = jsonstr.substr(0,valueLength);
while(JSON.stringify(segment).length> valueLength)
segment = jsonstr.substr(0,--valueLength);
storageObj [index] = segment;
jsonstr = jsonstr.substr(valueLength);
}
//存储所有的块
chrome.storage.sync.set(storageObj,callback);
$ b然后编写一个类似的提取函数,通过按键提取并将对象粘合在一起。
Is there any way to increase the chrome.storage.sync.QUOTA_BYTES_PER_ITEM ?
For me, the default 4096 Bytes is a little bit short.
I tried to execute
chrome.storage.sync.QUOTA_BYTES_PER_ITEM = 8192;
However, it seems that the actual limit doesn't change.
How can I do this?
解决方案 No, QUOTA_BYTES_PER_ITEM
is there for reference only; it is not a settable value. You could use the value of QUOTA_BYTES_PER_ITEM
to split an item up into multiple items, though:
function syncStore(key, objectToStore, callback) {
var jsonstr = JSON.stringify(objectToStore);
var i = 0;
var storageObj = {};
// split jsonstr into chunks and store them in an object indexed by `key_i`
while(jsonstr.length > 0) {
var index = key + "_" + i++;
// since the key uses up some per-item quota, see how much is left for the value
// also trim off 2 for quotes added by storage-time `stringify`
var valueLength = chrome.storage.sync.QUOTA_BYTES_PER_ITEM - index.length - 2;
// trim down segment so it will be small enough even when run through `JSON.stringify` again at storage time
var segment = jsonstr.substr(0, valueLength);
while(JSON.stringify(segment).length > valueLength)
segment = jsonstr.substr(0, --valueLength);
storageObj[index] = segment;
jsonstr = jsonstr.substr(valueLength);
}
// store all the chunks
chrome.storage.sync.set(storageObj, callback);
}
Then write an analogous fetch function that fetches by key and glues the object back together.
这篇关于我可以在Chrome中增加QUOTA_BYTES_PER_ITEM吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!