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