Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
tsc/idb-cache.js
.idea/
49 changes: 43 additions & 6 deletions dist/browser/idb-cache.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/browser/idb-cache.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/idb-cache.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 36 additions & 8 deletions dist/cjs/idb-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,28 @@ function canUseBlob() {
return true;
}

class CryptoKeyCacheEntry {
get length() {
return this._length;
}
get key() {
return this._key;
}
get id() {
return this._id;
}
constructor(id, key, length) {
this._id = id;
this._key = key;
this._length = length;
}
}

/**
* @author Drecom Co.,Ltd. http://www.drecom.co.jp/
*
* Modified by Swisscom (Schweiz) AG (David Rupp)
* -> Forked and enhanced with CryptoKeyCacheEntry
*/
const VERSION = 1;
const STORE_NAME = {
Expand All @@ -32,10 +52,11 @@ const DATA_TYPE = {
STRING: 1,
ARRAYBUFFER: 2,
BLOB: 3,
CRYPTO_KEY: 4
};
const useBlob = canUseBlob();
class IDBCache {
constructor(dbName, strageLimit) {
constructor(dbName, storageLimit) {
this._maxSize = 52428800; // 50MB
this._maxCount = 100; // 100files
this._defaultAge = 86400; // 1day
Expand All @@ -47,13 +68,13 @@ class IDBCache {
console.error('IndexedDB is not supported');
return;
}
if (strageLimit) {
if (strageLimit.size)
this._maxSize = strageLimit.size;
if (strageLimit.count)
this._maxCount = strageLimit.count;
if (strageLimit.defaultAge)
this._defaultAge = strageLimit.defaultAge;
if (storageLimit) {
if (storageLimit.size)
this._maxSize = storageLimit.size;
if (storageLimit.count)
this._maxCount = storageLimit.count;
if (storageLimit.defaultAge)
this._defaultAge = storageLimit.defaultAge;
}
this._initialize();
}
Expand Down Expand Up @@ -393,6 +414,10 @@ class IDBCache {
meta.type = DATA_TYPE.BLOB;
meta.size = data.size;
}
else if (data instanceof CryptoKeyCacheEntry) {
meta.type = DATA_TYPE.CRYPTO_KEY;
meta.size = data.length;
}
else {
console.warn('Is not supported type of value');
}
Expand Down Expand Up @@ -426,6 +451,9 @@ class IDBCache {
else if (data instanceof Blob) {
type = DATA_TYPE.BLOB;
}
else if (data instanceof CryptoKeyCacheEntry) {
type = DATA_TYPE.CRYPTO_KEY;
}
if (meta && meta.type === DATA_TYPE.BLOB && type === DATA_TYPE.ARRAYBUFFER) {
const blob = new Blob([data], { type: meta.mime });
cb(blob);
Expand Down
Loading