chrome-remote-cache
Advanced tools
Comparing version 0.0.4 to 0.1.0
{ | ||
"name": "chrome-remote-cache", | ||
"version": "0.0.4", | ||
"version": "0.1.0", | ||
"description": "Caching system for chrome devtools protocol", | ||
@@ -20,15 +20,21 @@ "keywords": [ | ||
"types": "src/index.d.ts", | ||
"scripts": { | ||
"test": "ava", | ||
"clean": "rimraf {test,lib,src,scripts}/*.{d.ts,js,js.map} ./index.{js,d.ts,js.map}", | ||
"rebuild": "npm run clean && tsc", | ||
"prepare": "npm run clean && tsc && ava" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"@u4/chrome-remote-interface": "^0.3.3", | ||
"ioredis": "^5.2.2", | ||
"@u4/chrome-remote-interface": "^0.4.6", | ||
"ioredis": "^5.2.3", | ||
"picocolors": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^18.6.2", | ||
"@types/node": "^18.8.4", | ||
"ava": "3.15.0", | ||
"rimraf": "^3.0.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^4.7.4" | ||
"typescript": "^4.8.4" | ||
}, | ||
@@ -51,8 +57,3 @@ "ava": { | ||
"src/*.d.ts" | ||
], | ||
"scripts": { | ||
"test": "ava", | ||
"clean": "rimraf {test,lib,src,scripts}/*.{d.ts,js,js.map} ./index.{js,d.ts,js.map}", | ||
"rebuild": "npm run clean && tsc" | ||
} | ||
] | ||
} |
@@ -12,3 +12,3 @@ #chrome-remote-cache | ||
import ChromeRemoteCache from "./ChromeRemoteCache"; | ||
import CacheManager from "./CacheManager"; | ||
import CacheManagerRedisTTL from "./CacheManager"; | ||
@@ -20,3 +20,3 @@ const delay = (ms: number) => new Promise((r) => setTimeout(r, ms)); | ||
const page = await devtools.connectNewPage(); | ||
const cm = new CacheManager(new Redis()); | ||
const cm = new CacheManagerRedisTTL(new Redis()); | ||
const remoteCache = new ChromeRemoteCache(cm); | ||
@@ -23,0 +23,0 @@ remoteCache.cache('www.google.com/maps/dir///'); |
/// <reference types="node" /> | ||
import Redis from 'ioredis'; | ||
export declare class CacheManager { | ||
private redis; | ||
constructor(redis?: Redis); | ||
export interface CacheManager { | ||
close(): void; | ||
@@ -11,4 +8,4 @@ getCacheMeta(cachekey?: [string, string] | null): Promise<string | null>; | ||
setCacheData([domain, path]: [string, string], data: Buffer): Promise<void>; | ||
cacheIncUsage([domain, path]: [string, string], inc?: number): Promise<number>; | ||
cacheIncUsage([domain, path]: [string, string], inc: number): Promise<number>; | ||
} | ||
export default CacheManager; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CacheManager = void 0; | ||
const ioredis_1 = __importDefault(require("ioredis")); | ||
// export const redis = new Redis(); | ||
const KEY_DATA = 'data:'; | ||
const KEY_META = 'meta:'; | ||
const KEY_COUNTER = 'usage:'; | ||
class CacheManager { | ||
redis; | ||
constructor(redis = new ioredis_1.default()) { | ||
this.redis = redis; | ||
} | ||
close() { | ||
this.redis.disconnect(); | ||
} | ||
async getCacheMeta(cachekey) { | ||
if (!cachekey) | ||
return null; | ||
const [domain, path] = cachekey; | ||
// const [domain, path] = splitUrl(textUrl); | ||
const key = KEY_META + domain; | ||
const cached = await this.redis.hget(key, path); | ||
return cached; | ||
} | ||
async getCacheData([domain, path]) { | ||
// const [domain, path] = splitUrl(textUrl); | ||
const key = KEY_DATA + domain; | ||
const cached = await this.redis.hgetBuffer(key, path); | ||
return cached; | ||
} | ||
async setCacheMeta([domain, path], cacheData) { | ||
// const [domain, path] = splitUrl(textUrl); | ||
const key = KEY_META + domain; | ||
await this.redis.hset(key, [path, cacheData]); | ||
} | ||
async setCacheData([domain, path], data) { | ||
// const [domain, path] = splitUrl(textUrl); | ||
const key = KEY_DATA + domain; | ||
await this.redis.hset(key, [path, data]); | ||
} | ||
async cacheIncUsage([domain, path], inc = 1) { | ||
// const [domain, path] = splitUrl(textUrl); | ||
const key = KEY_COUNTER + domain; | ||
const cnt = await this.redis.hincrby(key, path, inc); | ||
return cnt; | ||
} | ||
} | ||
exports.CacheManager = CacheManager; | ||
exports.default = CacheManager; |
@@ -1,4 +0,4 @@ | ||
import { CacheManager } from './CacheManager'; | ||
import { CacheStat } from './CacheStat'; | ||
import { Chrome } from "@u4/chrome-remote-interface"; | ||
import CacheManagerRedisTTL from './CacheManagerRedisTTL'; | ||
export declare class ChromeRemoteCache { | ||
@@ -12,3 +12,3 @@ #private; | ||
private statPassthrough; | ||
constructor(cm?: CacheManager); | ||
constructor(cm?: CacheManagerRedisTTL); | ||
close(): void; | ||
@@ -15,0 +15,0 @@ set logFnc(fnc: (message: string) => void); |
@@ -10,4 +10,4 @@ "use strict"; | ||
const UrlSet_1 = __importDefault(require("./UrlSet")); | ||
const CacheManager_1 = require("./CacheManager"); | ||
const CacheStat_1 = require("./CacheStat"); | ||
const CacheManagerRedisTTL_1 = __importDefault(require("./CacheManagerRedisTTL")); | ||
const dummy = (url) => url; | ||
@@ -30,3 +30,3 @@ const PREFIXS = { | ||
#logfnc = console.log; | ||
constructor(cm = new CacheManager_1.CacheManager()) { | ||
constructor(cm = new CacheManagerRedisTTL_1.default()) { | ||
this.cm = cm; | ||
@@ -33,0 +33,0 @@ } |
export { ChromeRemoteCache } from './ChromeRemoteCache'; | ||
export { CacheStat } from './CacheStat'; | ||
export { CacheManager } from './CacheManager'; | ||
export { CacheManagerRedisLongTerm } from './CacheManagerRedisLongTerm'; | ||
export { CacheManagerRedisTTL } from './CacheManagerRedisTTL'; | ||
export { dropQueryParam, formatSize } from './CacheUtils'; | ||
export { ChromeRemoteCache as default } from './ChromeRemoteCache'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.default = exports.formatSize = exports.dropQueryParam = exports.CacheManager = exports.CacheStat = exports.ChromeRemoteCache = void 0; | ||
exports.default = exports.formatSize = exports.dropQueryParam = exports.CacheManagerRedisTTL = exports.CacheManagerRedisLongTerm = exports.CacheStat = exports.ChromeRemoteCache = void 0; | ||
var ChromeRemoteCache_1 = require("./ChromeRemoteCache"); | ||
@@ -8,4 +8,6 @@ Object.defineProperty(exports, "ChromeRemoteCache", { enumerable: true, get: function () { return ChromeRemoteCache_1.ChromeRemoteCache; } }); | ||
Object.defineProperty(exports, "CacheStat", { enumerable: true, get: function () { return CacheStat_1.CacheStat; } }); | ||
var CacheManager_1 = require("./CacheManager"); | ||
Object.defineProperty(exports, "CacheManager", { enumerable: true, get: function () { return CacheManager_1.CacheManager; } }); | ||
var CacheManagerRedisLongTerm_1 = require("./CacheManagerRedisLongTerm"); | ||
Object.defineProperty(exports, "CacheManagerRedisLongTerm", { enumerable: true, get: function () { return CacheManagerRedisLongTerm_1.CacheManagerRedisLongTerm; } }); | ||
var CacheManagerRedisTTL_1 = require("./CacheManagerRedisTTL"); | ||
Object.defineProperty(exports, "CacheManagerRedisTTL", { enumerable: true, get: function () { return CacheManagerRedisTTL_1.CacheManagerRedisTTL; } }); | ||
var CacheUtils_1 = require("./CacheUtils"); | ||
@@ -12,0 +14,0 @@ Object.defineProperty(exports, "dropQueryParam", { enumerable: true, get: function () { return CacheUtils_1.dropQueryParam; } }); |
31742
20
825
+ Added@deno/shim-deno@0.9.0(transitive)
+ Added@deno/shim-deno-test@0.3.3(transitive)
+ Added@u4/chrome-remote-interface@0.4.10(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedwhich@2.0.2(transitive)
- Removed@u4/chrome-remote-interface@0.3.4(transitive)
- Removedcommander@9.4.1(transitive)
Updatedioredis@^5.2.3