emscripten Humble Cloud interface
Edward Rudd
2014-09-15 67627391daff8c2a589fb62ad4baadd11ac96714

add helper method to delete entries in the cache by a specific scope.

1 files modified
24 ■■■■■ changed files
client/library/library_humble.js 24 ●●●●● patch | view | raw | blame | history
client/library/library_humble.js
@@ -45,6 +45,30 @@
                return { path: path.path, scope: path.scope, key: path.scope + ':' + path.path };
            }
        },
        // deletes all entries for the specified scope
        clearCacheByScope: function(scope, oncomplete) {
            HUMBLE_API.getDB(function(err, db) {
                if (err) return oncomplete(err);
                var transaction = db.transaction([HUMBLE_API.DB_ASYNC_CACHE_STORE], 'readwrite');
                transaction.onerror = function() { oncomplete(this.error); };
                var store = transaction.objectStore(HUMBLE_API.DB_ASYNC_CACHE_STORE);
                var index = store.index('scope');
                index.openKeyCursor(IDBKeyRange.only(scope)).onsuccess = function(e) {
                    var cursor = event.target.result;
                    if (cursor) {
                        store.delete(cursor.primaryKey);
                        cursor.continue();
                    } else {
                        oncomplete(null);
                    }
                };
            });
        },
        storeToCache: function(path, byteArray, ondone) {
            if (path === null) {
                return ondone(null);