1 |
|
2 |
|
3 | import { StorageHelper } from '@aws-amplify/core';
|
4 |
|
5 |
|
6 |
|
7 | export var defaultConfig = {
|
8 | keyPrefix: 'aws-amplify-cache',
|
9 | capacityInBytes: 1048576,
|
10 | itemMaxSize: 210000,
|
11 | defaultTTL: 259200000,
|
12 | defaultPriority: 5,
|
13 | warningThreshold: 0.8,
|
14 |
|
15 |
|
16 | storage: new StorageHelper().getStorage(),
|
17 | };
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export function getByteLength(str) {
|
23 | var ret = 0;
|
24 | ret = str.length;
|
25 | for (var i = str.length; i >= 0; i -= 1) {
|
26 | var charCode = str.charCodeAt(i);
|
27 | if (charCode > 0x7f && charCode <= 0x7ff) {
|
28 | ret += 1;
|
29 | }
|
30 | else if (charCode > 0x7ff && charCode <= 0xffff) {
|
31 | ret += 2;
|
32 | }
|
33 |
|
34 | if (charCode >= 0xdc00 && charCode <= 0xdfff) {
|
35 | i -= 1;
|
36 | }
|
37 | }
|
38 | return ret;
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 | export function getCurrTime() {
|
44 | var currTime = new Date();
|
45 | return currTime.getTime();
|
46 | }
|
47 |
|
48 |
|
49 |
|
50 | export function isInteger(value) {
|
51 | if (Number.isInteger) {
|
52 | return Number.isInteger(value);
|
53 | }
|
54 | return _isInteger(value);
|
55 | }
|
56 | function _isInteger(value) {
|
57 | return (typeof value === 'number' && isFinite(value) && Math.floor(value) === value);
|
58 | }
|
59 |
|
60 |
|
61 |
|
62 | var store = {};
|
63 | var CacheObject = (function () {
|
64 | function CacheObject() {
|
65 | }
|
66 | CacheObject.clear = function () {
|
67 | store = {};
|
68 | };
|
69 | CacheObject.getItem = function (key) {
|
70 | return store[key] || null;
|
71 | };
|
72 | CacheObject.setItem = function (key, value) {
|
73 | store[key] = value;
|
74 | };
|
75 | CacheObject.removeItem = function (key) {
|
76 | delete store[key];
|
77 | };
|
78 | return CacheObject;
|
79 | }());
|
80 | export { CacheObject };
|
81 |
|
\ | No newline at end of file |