Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@composite-fetcher/with-caching

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@composite-fetcher/with-caching - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

14

./dist/index.js

@@ -40,2 +40,3 @@ // src/drivers/InMemoryCacheDriver.ts

return {
url: response.url,
status: response.status,

@@ -60,2 +61,3 @@ statusText: response.statusText,

const item = {
url: response.url,
value: await response.clone().text(),

@@ -105,4 +107,5 @@ headers: Array.from(response.headers.entries()),

// 10 minutes
constructor(cacheDriver, defaultTTL) {
constructor(options = {}) {
super();
const { cacheDriver, defaultTTL } = options;
this.cacheDriver = cacheDriver || new InMemoryCacheDriver();

@@ -124,4 +127,3 @@ if (defaultTTL) {

async onPreRequest(context) {
if (context.request.headers.has("x-no-cache")) {
context.next();
if (context.request.headers.has("x-fetcher-no-cache")) {
return;

@@ -136,8 +138,7 @@ }

}
context.next();
}
async onPostRequest(context) {
const { response, originalRequest } = context;
if (!originalRequest.headers.has("x-no-cache") && response.ok) {
const cacheTTL = originalRequest.headers.has("x-cache-ttl") ? Number(originalRequest.headers.get("x-cache-ttl")) : this.defaultTTL;
if (!originalRequest.headers.has("x-fetcher-no-cache") && response.ok) {
const cacheTTL = originalRequest.headers.has("x-fetcher-cache-ttl") ? Number(originalRequest.headers.get("x-fetcher-cache-ttl")) : this.defaultTTL;
const cacheKey = await this.generateCacheKey(context.originalRequest);

@@ -150,3 +151,2 @@ await this.cacheDriver.set(

}
context.next();
}

@@ -153,0 +153,0 @@ };

@@ -10,2 +10,6 @@ import { BasePlugin, PluginHandlerContext, PluginLifecycleHook } from '@composite-fetcher/core';

}
interface withCachingOptions {
cacheDriver?: CacheDriver;
defaultTTL?: number;
}

@@ -35,3 +39,3 @@ declare class InMemoryCacheDriver implements CacheDriver {

private readonly defaultTTL;
constructor(cacheDriver?: CacheDriver, defaultTTL?: number);
constructor(options?: withCachingOptions);
private generateCacheKey;

@@ -43,2 +47,2 @@ private getCacheTTL;

export { CacheDriver, InMemoryCacheDriver, SessionStorageDriver, withCachingPlugin as withCaching };
export { CacheDriver, InMemoryCacheDriver, SessionStorageDriver, withCachingPlugin as withCaching, withCachingOptions };

@@ -40,2 +40,3 @@ // src/drivers/InMemoryCacheDriver.ts

return {
url: response.url,
status: response.status,

@@ -60,2 +61,3 @@ statusText: response.statusText,

const item = {
url: response.url,
value: await response.clone().text(),

@@ -105,4 +107,5 @@ headers: Array.from(response.headers.entries()),

// 10 minutes
constructor(cacheDriver, defaultTTL) {
constructor(options = {}) {
super();
const { cacheDriver, defaultTTL } = options;
this.cacheDriver = cacheDriver || new InMemoryCacheDriver();

@@ -124,4 +127,3 @@ if (defaultTTL) {

async onPreRequest(context) {
if (context.request.headers.has("x-no-cache")) {
context.next();
if (context.request.headers.has("x-fetcher-no-cache")) {
return;

@@ -136,8 +138,7 @@ }

}
context.next();
}
async onPostRequest(context) {
const { response, originalRequest } = context;
if (!originalRequest.headers.has("x-no-cache") && response.ok) {
const cacheTTL = originalRequest.headers.has("x-cache-ttl") ? Number(originalRequest.headers.get("x-cache-ttl")) : this.defaultTTL;
if (!originalRequest.headers.has("x-fetcher-no-cache") && response.ok) {
const cacheTTL = originalRequest.headers.has("x-fetcher-cache-ttl") ? Number(originalRequest.headers.get("x-fetcher-cache-ttl")) : this.defaultTTL;
const cacheKey = await this.generateCacheKey(context.originalRequest);

@@ -150,3 +151,2 @@ await this.cacheDriver.set(

}
context.next();
}

@@ -153,0 +153,0 @@ };

{
"name": "@composite-fetcher/with-caching",
"description": "withCaching is a simple fetcher core plugin to manage request caching with different drivers",
"version": "0.1.0",
"version": "0.1.1",
"author": "Teofanis Papadopulos",

@@ -33,3 +33,3 @@ "type": "module",

"dependencies": {
"@composite-fetcher/core": "^0.1.4"
"@composite-fetcher/core": "^0.1.5"
},

@@ -36,0 +36,0 @@ "scripts": {

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