Socket
Socket
Sign inDemoInstall

simple-in-memory-cache

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-in-memory-cache - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

10

dist/cache.d.ts

@@ -0,6 +1,8 @@

import type { PickOne } from 'type-fns';
export interface SimpleInMemoryCache<T> {
get: (key: string) => T | undefined;
set: (key: string, value: T, options?: {
set: (key: string, value: T, options?: Partial<PickOne<{
secondsUntilExpiration?: number;
}) => void;
seconds?: number;
}>>) => void;
keys: () => string[];

@@ -14,3 +16,3 @@ }

}
export declare const createCache: <T>({ seconds, defaultSecondsUntilExpiration: defaultSecondsUntilExpirationInput, }?: {
export declare const createCache: <T>({ seconds, defaultSecondsUntilExpiration: defaultSecondsUntilExpirationInput, }?: Partial<PickOne<{
/**

@@ -27,2 +29,2 @@ * the number of seconds items in the cache expire after

seconds?: number | undefined;
}) => SimpleInMemoryCache<T>;
}>>) => SimpleInMemoryCache<T>;

2

dist/cache.js

@@ -27,3 +27,3 @@ "use strict";

return undefined; // if not in cache, then undefined
if (cacheContent.expiresAtMse < getMseNow())
if (cacheContent.expiresAtMse <= getMseNow())
return undefined; // if already expired, then undefined

@@ -30,0 +30,0 @@ return cacheContent.value; // otherwise, its in the cache and not expired, so return the value

@@ -71,2 +71,17 @@ "use strict";

}));
it('should consider secondsUntilExpiration of null or infinity as never expiring', () => __awaiter(void 0, void 0, void 0, function* () {
const { set, get } = (0, cache_1.createCache)({
defaultSecondsUntilExpiration: 0, // expire immediately
});
// prove that setting something to the cache with default state will have it expired immediately
yield set('dory-memory', 'something'); // lets see if dory can remember something
const doryMemory = yield get('dory-memory');
expect(doryMemory).toEqual(undefined); // its already gone! dang default expiration
// prove that if we record the memory with expires-at Infinity, it persists
yield set('elephant-memory', 'something', {
secondsUntilExpiration: Infinity,
});
const elephantMemory = yield get('elephant-memory');
expect(elephantMemory).toEqual('something');
}));
it('should accurately get keys', () => {

@@ -73,0 +88,0 @@ // create the cache

@@ -5,3 +5,3 @@ {

"description": "A simple in-memory cache, for nodejs and the browser, with time based expiration policies.",
"version": "0.3.1",
"version": "0.3.2",
"repository": "ehmpathy/simple-in-memory-cache",

@@ -80,2 +80,3 @@ "homepage": "https://github.com/ehmpathy/simple-in-memory-cache",

"ts-node": "10.9.1",
"type-fns": "^1.19.0",
"typescript": "4.9.4"

@@ -82,0 +83,0 @@ },

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