IndexedDb存储重置为.clear(),但配额永不减少

时间:2014-08-30 12:24:31

标签: javascript html5 indexeddb

我尝试在Chrome中使用IndexedDb数据库存储撤消点(非常大的数据类型数组)。

由于撤消信息只有一个会话生命周期,因此每次初始化应用程序时都会清除商店。一切似乎都运行正常,但当我查询配额时,似乎总是在不断减少。我知道商店已被清除,因为如果我使用游标,则其中没有其他键。

减少配额的唯一方法是从“设置”菜单中手动删除数据库。

清除商店是否不足以释放来源并重新设置配额?这是我的代码在init处的作用:

        idxdDB.open = function () {
        var version = 1;
        var request = indexedDB.open("db_undo", version);

        // We can only create Object stores in a versionchange transaction.
        request.onupgradeneeded = function (e) {
            var db = e.target.result;

            // A versionchange transaction is started automatically.
            e.target.transaction.onerror = function (e) {
                console.log("Error", e);
            };

            if (db.objectStoreNames.contains("undo_point")) {
                db.deleteObjectStore("undo_point");
            }

            var store = db.createObjectStore("undo_point");
        };

        request.onsuccess = function (e) {
            idxdDB.db = e.target.result;

            // Clear the store
            var trans = idxdDB.db.transaction(["undo_point"], "readwrite");
            var store = trans.objectStore("undo_point");

            var req = store.clear();
            req.onsuccess = function(evt) {
                console.log("Store cleared");
                getQuota();
                listAllStore(store);
            };

        };

        request.onerror = function (e) {
            console.log("Error!", e);
        };
    };

以下是我用来查询配额并列出商店中所有条目的内容:

function getQuota () {
      if (window.webkitStorageInfo && window.webkitStorageInfo.queryUsageAndQuota) {
        window.webkitStorageInfo.queryUsageAndQuota(webkitStorageInfo.TEMPORARY,
          function (used, remaining) {
              console.log("Used quota: " + used + ", remaining quota: " + remaining);
          }, function (e) {
              console.log('Error', e);
          });
      }
    }


function listAllStore (store) {
        store.openCursor().onsuccess = function(event) {
            var cursor = event.target.result;
                // if there is still another cursor to go, keep runing this code
                if(cursor) {
                    console.log (cursor);

                    // continue on to the next item in the cursor
                    cursor.continue();

                    // if there are no more cursor items to iterate through, say so, and exit the function 
                } else {
                    console.log ("Cursor finished");
                }
        }
    }

0 个答案:

没有答案