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

memoize-fs

Package Overview
Dependencies
Maintainers
0
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoize-fs - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

2

package.json
{
"name": "memoize-fs",
"version": "4.0.1",
"version": "4.1.0",
"private": false,

@@ -5,0 +5,0 @@ "type": "module",

@@ -73,2 +73,3 @@ # memoize-fs

// fn: [AsyncFunction: fn],
// cacheHit: [Getter],
// getCacheFilePath: [Function: t],

@@ -94,3 +95,3 @@ // invalidate: [AsyncFunction: e]

const memFn = await memoize.fn(funAsync)
const memFn = await memoizer.fn(funAsync)

@@ -135,3 +136,3 @@ await memFn(1, 2, function (err, sum) { if (err) { throw err; } console.log(sum); })

```ts
export interface MemoizerOptions {
interface MemoizerOptions {
cacheId: string

@@ -150,11 +151,3 @@ cachePath: string

export declare function getCacheFilePath(
fn: unknown,
args: unknown[],
opt: Partial<MemoizerOptions>
): string
export default function buildMemoizer(
memoizerOptions: Partial<MemoizerOptions>
): {
interface Memoizer {
fn: <FN extends (...args: never) => unknown>(

@@ -164,2 +157,3 @@ fn: FN,

) => Promise<(...args: Parameters<FN>) => Promise<Awaited<ReturnType<FN>>>>
readonly cacheHit: boolean | undefined
getCacheFilePath: (

@@ -300,2 +294,34 @@ fn: (...args: never) => unknown,

## Checking for a cache hit
You can check if the result of a momoized function resulted from a cache hit using the `cacheHit` getter on the `Memoizer` instance. Initially, if no memoized function has been executed, `cacheHit` is `undefined`; if the result of a memozed function was read from a cache file, `cacheHit` is `true`; if the result was just written to a cache file, `cacheHit` is `true`; if an exceptions occured, `cacheHit` is `undefined`.
```js
import memoizeFs from 'memoize-fs'
import assert from 'node:assert'
const memoizer = memoizeFs({ cachePath: './some-cache' })
;(async () => {
let idx = 0
const func = function foo(a, b) {
idx += a + b
return idx
}
const memoizedFn = await memoizer.fn(func)
assert.strictEqual(memoizer.cacheHit, undefined)
const resultOne = await memoizedFn(1, 2)
assert.strictEqual(memoizer.cacheHit, false)
assert.strictEqual(resultOne, 3)
assert.strictEqual(idx, 3)
const resultTwo = await memoizedFn(1, 2)
assert.strictEqual(memoizer.cacheHit, true)
assert.strictEqual(resultTwo, 3)
assert.strictEqual(idx, 3)
})()
```
## Serialization

@@ -302,0 +328,0 @@

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