@8ms/helpers 1.3.28 → 1.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,10 +3,9 @@ import { GetKey } from './getKey';
|
|
|
3
3
|
type GetCache = GetKey & {
|
|
4
4
|
bucket: string;
|
|
5
5
|
cache: Cache;
|
|
6
|
-
isJson?: boolean;
|
|
7
6
|
};
|
|
8
7
|
/**
|
|
9
8
|
* Get the stored cache if it exists.
|
|
10
9
|
*/
|
|
11
|
-
declare const getCache: ({ bucket, cache, fileName, folder
|
|
10
|
+
declare const getCache: ({ bucket, cache, fileName, folder }: GetCache) => Promise<any>;
|
|
12
11
|
export default getCache;
|
package/aws/s3cache/getCache.js
CHANGED
|
@@ -10,7 +10,7 @@ const getBrotliDecompressed_1 = __importDefault(require("../../util/getBrotliDec
|
|
|
10
10
|
/**
|
|
11
11
|
* Get the stored cache if it exists.
|
|
12
12
|
*/
|
|
13
|
-
const getCache = async ({ bucket, cache, fileName, folder
|
|
13
|
+
const getCache = async ({ bucket, cache, fileName, folder }) => {
|
|
14
14
|
let response = undefined;
|
|
15
15
|
// Store the cache key
|
|
16
16
|
const s3CacheKey = (0, getKey_1.default)({ fileName, folder });
|
|
@@ -18,12 +18,14 @@ const getCache = async ({ bucket, cache, fileName, folder, isJson }) => {
|
|
|
18
18
|
if (cache) {
|
|
19
19
|
// Try to get the cache
|
|
20
20
|
try {
|
|
21
|
-
const cached = await (0, readFile_1.default)({ bucket, key: s3CacheKey, isJson });
|
|
21
|
+
const cached = await (0, readFile_1.default)({ bucket, key: s3CacheKey, isJson: false });
|
|
22
22
|
// Cache exists and is still within our caching timeframe
|
|
23
23
|
if (undefined !== cached.body && (durations_1.default.FOREVER === cache.timeframe || cached.modified[cache.from][cache.timeframe] < cache.duration)) {
|
|
24
|
-
|
|
24
|
+
const cachedBody = await (0, getBrotliDecompressed_1.default)({
|
|
25
25
|
input: cached.body,
|
|
26
26
|
});
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
response = JSON.parse(cachedBody);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
catch (error) {
|