Socket
Socket
Sign inDemoInstall

metro-cache

Package Overview
Dependencies
Maintainers
2
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metro-cache - npm Package Compare versions

Comparing version 0.80.9 to 0.80.10

9

package.json
{
"name": "metro-cache",
"version": "0.80.9",
"version": "0.80.10",
"description": "🚇 Cache layers for Metro.",

@@ -15,7 +15,8 @@ "main": "src/index.js",

"dependencies": {
"metro-core": "0.80.9",
"rimraf": "^3.0.2"
"exponential-backoff": "^3.1.1",
"flow-enums-runtime": "^0.0.6",
"metro-core": "0.80.10"
},
"devDependencies": {
"metro-memory-fs": "0.80.9"
"metro-memory-fs": "0.80.10"
},

@@ -22,0 +23,0 @@ "license": "MIT",

@@ -14,3 +14,4 @@ "use strict";

const store = stores[i];
const name = store.constructor.name + "::" + key.toString("hex");
const storeName = store.name ?? store.constructor.name;
const name = storeName + "::" + key.toString("hex");
let value = null;

@@ -31,6 +32,10 @@ const logStart = Logger.log(

} finally {
Logger.log(Logger.createActionEndEntry(logStart));
const hitOrMiss = value != null ? "hit" : "miss";
Logger.log({
...Logger.createActionEndEntry(logStart),
action_result: hitOrMiss,
});
Logger.log(
Logger.createEntry({
action_name: "Cache " + (value == null ? "miss" : "hit"),
action_name: "Cache " + hitOrMiss,
log_entry_label: name,

@@ -52,7 +57,10 @@ })

const promises = [];
const writeErrors = [];
const storesWithErrors = new Set();
for (let i = 0; i < length && stores[i] !== stop; i++) {
const store = stores[i];
const name = store.constructor.name + "::" + key.toString("hex");
Logger.log(
Logger.createEntry({
const storeName = store.name ?? store.constructor.name;
const name = storeName + "::" + key.toString("hex");
const logStart = Logger.log(
Logger.createActionStartEntry({
action_name: "Cache set",

@@ -62,5 +70,28 @@ log_entry_label: name,

);
promises.push(stores[i].set(key, value));
promises.push(
(async () => {
try {
await stores[i].set(key, value);
Logger.log(Logger.createActionEndEntry(logStart));
} catch (e) {
Logger.log(Logger.createActionEndEntry(logStart, e));
storesWithErrors.add(storeName);
writeErrors.push(
new Error(`Cache write failed for ${name}`, {
cause: e,
})
);
}
})()
);
}
await Promise.all(promises);
await Promise.allSettled(promises);
if (writeErrors.length > 0) {
throw new AggregateError(
writeErrors,
`Cache write failed for store(s): ${Array.from(storesWithErrors).join(
", "
)}`
);
}
}

@@ -67,0 +98,0 @@ get isDisabled() {

@@ -5,3 +5,2 @@ "use strict";

const path = require("path");
const rimraf = require("rimraf");
const NULL_BYTE = 0x00;

@@ -72,3 +71,6 @@ const NULL_BYTE_BUFFER = Buffer.from([NULL_BYTE]);

for (let i = 0; i < 256; i++) {
rimraf.sync(path.join(this._root, ("0" + i.toString(16)).slice(-2)));
fs.rmSync(path.join(this._root, ("0" + i.toString(16)).slice(-2)), {
force: true,
recursive: true,
});
}

@@ -75,0 +77,0 @@ }

@@ -5,2 +5,3 @@ "use strict";

const NetworkError = require("./NetworkError");
const { backOff } = require("exponential-backoff");
const http = require("http");

@@ -61,5 +62,11 @@ const https = require("https");

debug: options.debug ?? false,
maxAttempts: options.maxAttempts ?? 1,
retryStatuses: new Set(options.retryStatuses ?? []),
retryNetworkErrors: options.retryNetworkErrors ?? false,
};
}
get(key) {
return this.#withRetries(() => this.#getOnce(key), this._getEndpoint);
}
#getOnce(key) {
return new Promise((resolve, reject) => {

@@ -165,2 +172,8 @@ let searchParamsString = this._getEndpoint.params.toString();

set(key, value) {
return this.#withRetries(
() => this.#setOnce(key, value),
this._setEndpoint
);
}
#setOnce(key, value) {
return new Promise((resolve, reject) => {

@@ -253,3 +266,21 @@ const gzip = zlib.createGzip(ZLIB_OPTIONS);

clear() {}
#withRetries(fn, endpoint) {
if (endpoint.maxAttempts === 1) {
return fn();
}
return backOff(fn, {
jitter: "full",
maxDelay: 30000,
numOfAttempts: this._getEndpoint.maxAttempts || Number.POSITIVE_INFINITY,
retry: (e) => {
if (e instanceof HttpError) {
return this._getEndpoint.retryStatuses.has(e.code);
}
return (
e instanceof NetworkError && this._getEndpoint.retryNetworkErrors
);
},
});
}
}
module.exports = HttpStore;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc