Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript IndexedDb存储区使用.clear()重置,但配额从不减少_Javascript_Html_Indexeddb - Fatal编程技术网

Javascript IndexedDb存储区使用.clear()重置,但配额从不减少

Javascript IndexedDb存储区使用.clear()重置,但配额从不减少,javascript,html,indexeddb,Javascript,Html,Indexeddb,我试图使用Chrome中的IndexedDb数据库来存储撤销点(非常大的数据类型数组) 由于“撤消信息”只有一个会话生存期,因此每次初始化应用程序时,我都会清除存储。一切似乎都正常,但当我查询配额时,它似乎总是在不断减少。我知道存储区已被清除,因为如果我使用光标,其中就没有更多的键 减少配额的唯一方法是从“设置”菜单中手动删除数据库 清除存储是否不足以释放源并重新设置配额?以下是我的代码在init中的作用: idxdDB.open = function () {

我试图使用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");
                }
        }
    }

您是否尝试过
indexedDB.deleteDatabase('DB NAME')
Works。不过,我仍然不明白为什么清除数据库不能起到作用。