1 | import { StorageCache } from './StorageCache';
|
2 | import { ICache, CacheConfig, CacheItemOptions } from './types';
|
3 |
|
4 |
|
5 |
|
6 | export declare class BrowserStorageCacheClass extends StorageCache implements ICache {
|
7 | |
8 |
|
9 |
|
10 |
|
11 | constructor(config?: CacheConfig);
|
12 | /**
|
13 | * decrease current size of the cache
|
14 | *
|
15 | * @private
|
16 | * @param amount - the amount of the cache size which needs to be decreased
|
17 | */
|
18 | private _decreaseCurSizeInBytes;
|
19 | /**
|
20 | * increase current size of the cache
|
21 | *
|
22 | * @private
|
23 | * @param amount - the amount of the cache szie which need to be increased
|
24 | */
|
25 | private _increaseCurSizeInBytes;
|
26 | /**
|
27 | * update the visited time if item has been visited
|
28 | *
|
29 | * @private
|
30 | * @param item - the item which need to be refreshed
|
31 | * @param prefixedKey - the key of the item
|
32 | *
|
33 | * @return the refreshed item
|
34 | */
|
35 | private _refreshItem;
|
36 | /**
|
37 | * check wether item is expired
|
38 | *
|
39 | * @private
|
40 | * @param key - the key of the item
|
41 | *
|
42 | * @return true if the item is expired.
|
43 | */
|
44 | private _isExpired;
|
45 | /**
|
46 | * delete item from cache
|
47 | *
|
48 | * @private
|
49 | * @param prefixedKey - the key of the item
|
50 | * @param size - optional, the byte size of the item
|
51 | */
|
52 | private _removeItem;
|
53 | /**
|
54 | * put item into cache
|
55 | *
|
56 | * @private
|
57 | * @param prefixedKey - the key of the item
|
58 | * @param itemData - the value of the item
|
59 | * @param itemSizeInBytes - the byte size of the item
|
60 | */
|
61 | private _setItem;
|
62 | /**
|
63 | * total space needed when poping out items
|
64 | *
|
65 | * @private
|
66 | * @param itemSize
|
67 | *
|
68 | * @return total space needed
|
69 | */
|
70 | private _sizeToPop;
|
71 | /**
|
72 | * see whether cache is full
|
73 | *
|
74 | * @private
|
75 | * @param itemSize
|
76 | *
|
77 | * @return true if cache is full
|
78 | */
|
79 | private _isCacheFull;
|
80 | /**
|
81 | * scan the storage and find out all the keys owned by this cache
|
82 | * also clean the expired keys while scanning
|
83 | *
|
84 | * @private
|
85 | *
|
86 | * @return array of keys
|
87 | */
|
88 | private _findValidKeys;
|
89 | /**
|
90 | * get all the items we have, sort them by their priority,
|
91 | * if priority is same, sort them by their last visited time
|
92 | * pop out items from the low priority (5 is the lowest)
|
93 | *
|
94 | * @private
|
95 | * @param keys - all the keys in this cache
|
96 | * @param sizeToPop - the total size of the items which needed to be poped out
|
97 | */
|
98 | private _popOutItems;
|
99 | /**
|
100 | * Set item into cache. You can put number, string, boolean or object.
|
101 | * The cache will first check whether has the same key.
|
102 | * If it has, it will delete the old item and then put the new item in
|
103 | * The cache will pop out items if it is full
|
104 | * You can specify the cache item options. The cache will abort and output a warning:
|
105 | * If the key is invalid
|
106 | * If the size of the item exceeds itemMaxSize.
|
107 | * If the value is undefined
|
108 | * If incorrect cache item configuration
|
109 | * If error happened with browser storage
|
110 | *
|
111 | * @param key - the key of the item
|
112 | * @param value - the value of the item
|
113 | * @param {Object} [options] - optional, the specified meta-data
|
114 | */
|
115 | setItem(key: string, value: object | number | string | boolean, options?: CacheItemOptions): void;
|
116 | |
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | getItem(key: string, options?: CacheItemOptions): any;
|
132 | |
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 | removeItem(key: string): void;
|
139 | |
140 |
|
141 |
|
142 |
|
143 |
|
144 | clear(): void;
|
145 | |
146 |
|
147 |
|
148 |
|
149 |
|
150 | getAllKeys(): string[];
|
151 | |
152 |
|
153 |
|
154 |
|
155 |
|
156 | getCacheCurSize(): number;
|
157 | |
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 | createInstance(config: CacheConfig): ICache;
|
164 | }
|
165 | export declare const BrowserStorageCache: ICache;
|