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

@algolia/cache-common

Package Overview
Dependencies
Maintainers
60
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/cache-common - npm Package Compare versions

Comparing version 4.0.0-beta.9 to 4.0.0-beta.10

39

dist/cache-common.cjs.js

@@ -5,2 +5,31 @@ 'use strict';

// @todo Add logger on options to debug when caches go wrong.
function createFallbackableCache(options) {
const caches = [...options.caches];
// eslint-disable-next-line functional/immutable-data
const current = caches.shift();
if (current === undefined) {
return createNullCache();
}
return {
get(key, defaultValue, events = {
miss: () => Promise.resolve(),
}) {
return current.get(key, defaultValue, events).catch(() => {
return createFallbackableCache({ caches }).get(key, defaultValue, events);
});
},
set(key, value) {
return current.set(key, value).catch(() => {
return createFallbackableCache({ caches }).set(key, value);
});
},
delete(key) {
return current.delete(key).catch(() => {
return createFallbackableCache({ caches }).delete(key);
});
},
};
}
function createNullCache() {

@@ -13,6 +42,4 @@ return {

return value
.then(result => {
return Promise.all([events.miss(result), result]);
})
.then(results => results[1]);
.then(result => Promise.all([result, events.miss(result)]))
.then(([result]) => result);
},

@@ -25,8 +52,6 @@ set(_key, value) {

},
clear() {
return Promise.resolve();
},
};
}
exports.createFallbackableCache = createFallbackableCache;
exports.createNullCache = createNullCache;

14

dist/cache-common.d.ts

@@ -0,7 +1,7 @@

import { Cache as Cache_2 } from '@algolia/cache-common';
export declare type Cache = {
readonly get: <TValue>(key: object, defaultValue: () => Readonly<Promise<TValue>>, events?: CacheEvents<TValue>) => Readonly<Promise<TValue>>;
readonly set: <TValue>(key: object, value: TValue) => Readonly<Promise<TValue>>;
readonly delete: (key: object) => Readonly<Promise<void>>;
readonly clear: () => Readonly<Promise<void>>;
readonly get: <TValue>(key: object | string, defaultValue: () => Readonly<Promise<TValue>>, events?: CacheEvents<TValue>) => Readonly<Promise<TValue>>;
readonly set: <TValue>(key: object | string, value: TValue) => Readonly<Promise<TValue>>;
readonly delete: (key: object | string) => Readonly<Promise<void>>;
};

@@ -13,4 +13,10 @@

export declare function createFallbackableCache(options: FallbackableCacheOptions): Cache;
export declare function createNullCache(): Cache;
export declare type FallbackableCacheOptions = {
readonly caches: readonly Cache_2[];
};
export { }

@@ -0,1 +1,30 @@

// @todo Add logger on options to debug when caches go wrong.
function createFallbackableCache(options) {
const caches = [...options.caches];
// eslint-disable-next-line functional/immutable-data
const current = caches.shift();
if (current === undefined) {
return createNullCache();
}
return {
get(key, defaultValue, events = {
miss: () => Promise.resolve(),
}) {
return current.get(key, defaultValue, events).catch(() => {
return createFallbackableCache({ caches }).get(key, defaultValue, events);
});
},
set(key, value) {
return current.set(key, value).catch(() => {
return createFallbackableCache({ caches }).set(key, value);
});
},
delete(key) {
return current.delete(key).catch(() => {
return createFallbackableCache({ caches }).delete(key);
});
},
};
}
function createNullCache() {

@@ -8,6 +37,4 @@ return {

return value
.then(result => {
return Promise.all([events.miss(result), result]);
})
.then(results => results[1]);
.then(result => Promise.all([result, events.miss(result)]))
.then(([result]) => result);
},

@@ -20,8 +47,5 @@ set(_key, value) {

},
clear() {
return Promise.resolve();
},
};
}
export { createNullCache };
export { createFallbackableCache, createNullCache };
{
"name": "@algolia/cache-common",
"version": "4.0.0-beta.9",
"version": "4.0.0-beta.10",
"private": false,

@@ -5,0 +5,0 @@ "description": "Common interfaces for promise-based caching libraries",

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