@@ -20,8 +20,28 @@ function canUseBlob() {
20
20
return true ;
21
21
}
22
22
23
+ class CryptoKeyCacheEntry {
24
+ get length ( ) {
25
+ return this . _length ;
26
+ }
27
+ get key ( ) {
28
+ return this . _key ;
29
+ }
30
+ get id ( ) {
31
+ return this . _id ;
32
+ }
33
+ constructor ( id , key , length ) {
34
+ this . _id = id ;
35
+ this . _key = key ;
36
+ this . _length = length ;
37
+ }
38
+ }
39
+
23
40
/**
24
41
* @author Drecom Co.,Ltd. http://www.drecom.co.jp/
42
+ *
43
+ * Modified by Swisscom (Schweiz) AG (David Rupp)
44
+ * -> Forked and enhanced with CryptoKeyCacheEntry
25
45
*/
26
46
const VERSION = 1 ;
27
47
const STORE_NAME = {
@@ -32,10 +52,11 @@ const DATA_TYPE = {
32
52
STRING : 1 ,
33
53
ARRAYBUFFER : 2 ,
34
54
BLOB : 3 ,
55
+ CRYPTO_KEY : 4
35
56
} ;
36
57
const useBlob = canUseBlob ( ) ;
37
58
class IDBCache {
38
- constructor ( dbName , strageLimit ) {
59
+ constructor ( dbName , storageLimit ) {
39
60
this . _maxSize = 52428800 ; // 50MB
40
61
this . _maxCount = 100 ; // 100files
41
62
this . _defaultAge = 86400 ; // 1day
@@ -47,13 +68,13 @@ class IDBCache {
47
68
console . error ( 'IndexedDB is not supported' ) ;
48
69
return ;
49
70
}
50
- if ( strageLimit ) {
51
- if ( strageLimit . size )
52
- this . _maxSize = strageLimit . size ;
53
- if ( strageLimit . count )
54
- this . _maxCount = strageLimit . count ;
55
- if ( strageLimit . defaultAge )
56
- this . _defaultAge = strageLimit . defaultAge ;
71
+ if ( storageLimit ) {
72
+ if ( storageLimit . size )
73
+ this . _maxSize = storageLimit . size ;
74
+ if ( storageLimit . count )
75
+ this . _maxCount = storageLimit . count ;
76
+ if ( storageLimit . defaultAge )
77
+ this . _defaultAge = storageLimit . defaultAge ;
57
78
}
58
79
this . _initialize ( ) ;
59
80
}
@@ -393,6 +414,10 @@ class IDBCache {
393
414
meta . type = DATA_TYPE . BLOB ;
394
415
meta . size = data . size ;
395
416
}
417
+ else if ( data instanceof CryptoKeyCacheEntry ) {
418
+ meta . type = DATA_TYPE . CRYPTO_KEY ;
419
+ meta . size = data . length ;
420
+ }
396
421
else {
397
422
console . warn ( 'Is not supported type of value' ) ;
398
423
}
@@ -426,6 +451,9 @@ class IDBCache {
426
451
else if ( data instanceof Blob ) {
427
452
type = DATA_TYPE . BLOB ;
428
453
}
454
+ else if ( data instanceof CryptoKeyCacheEntry ) {
455
+ type = DATA_TYPE . CRYPTO_KEY ;
456
+ }
429
457
if ( meta && meta . type === DATA_TYPE . BLOB && type === DATA_TYPE . ARRAYBUFFER ) {
430
458
const blob = new Blob ( [ data ] , { type : meta . mime } ) ;
431
459
cb ( blob ) ;
0 commit comments