New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

memoize-fs

Package Overview
Dependencies
Maintainers
1
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 1.2.0 to 1.3.0

package-lock.json

4

CHANGELOG.md

@@ -0,1 +1,5 @@

### 1.3.0 (2017-08-26)
* exporting getCacheFilePath method
### 1.2.0 (2017-08-26)

@@ -2,0 +6,0 @@

59

index.js

@@ -11,3 +11,32 @@ 'use strict'

module.exports = function (options) {
module.exports = buildMemoizer
module.exports.getCacheFilePath = getCacheFilePath
function serialize (val) {
var circRefColl = []
return JSON.stringify(val, function (name, value) {
if (typeof value === 'function') {
return // ignore arguments and attributes of type function silently
}
if (typeof value === 'object' && value !== null) {
if (circRefColl.indexOf(value) !== -1) {
// circular reference found, discard key
return
}
// store value in collection
circRefColl.push(value)
}
return value
})
}
function getCacheFilePath (fn, args, opt) {
var salt = opt.salt || ''
var fnStr = (opt.noBody ? '' : opt.astBody ? JSON.stringify(parseScript(String(fn))) : String(fn))
var argsStr = serialize(args)
var hash = crypto.createHash('md5').update(fnStr + argsStr + salt).digest('hex')
return path.join(opt.cachePath, opt.cacheId, hash)
}
function buildMemoizer (options) {
// check args

@@ -34,28 +63,2 @@ if (typeof options !== 'object') {

function serialize (val) {
var circRefColl = []
return JSON.stringify(val, function (name, value) {
if (typeof value === 'function') {
return // ignore arguments and attributes of type function silently
}
if (typeof value === 'object' && value !== null) {
if (circRefColl.indexOf(value) !== -1) {
// circular reference found, discard key
return
}
// store value in collection
circRefColl.push(value)
}
return value
})
}
function getCacheFilePath (fn, args, opt) {
var salt = opt.salt || ''
var fnStr = (opt.noBody ? '' : opt.astBody ? JSON.stringify(parseScript(String(fn))) : String(fn))
var argsStr = serialize(args)
var hash = crypto.createHash('md5').update(fnStr + argsStr + salt).digest('hex')
return path.join(options.cachePath, opt.cacheId, hash)
}
function memoizeFn (fn, opt) {

@@ -98,3 +101,3 @@ function checkOptions (optExt) {

return new Promise(function (resolve, reject) {
var filePath = getCacheFilePath(fn, args, optExt)
var filePath = getCacheFilePath(fn, args, Object.assign({}, optExt, {cachePath: options.cachePath}))

@@ -101,0 +104,0 @@ function cacheAndReturn () {

{
"name": "memoize-fs",
"version": "1.2.0",
"version": "1.3.0",
"description": "memoize/cache in file system solution for Node.js",

@@ -5,0 +5,0 @@ "author": "Boris Diakur <contact@borisdiakur.com> (https://github.com/borisdiakur)",

@@ -55,3 +55,3 @@ # memoize-fs

memoise-fs assumes a function asynchronous if the last argument it accepts is of type `function` and that function itself accepts at least one argument.
memoize-fs assumes a function asynchronous if the last argument it accepts is of type `function` and that function itself accepts at least one argument.
So basically you don't have to do anything differently than when memoizing synchronous functions. Just make sure the above condition is fulfilled.

@@ -183,2 +183,11 @@ Here is an example of memoizing a function with a callback:

The hash is created from the serialized arguments, the function body and the [salt](#salt) (if provided as an option).
You can generate this hash using `memoize.getCacheFilePath`:
```js
var memoize = require('memoize-fs')
memoize.getCacheFilePath(function () {}, ['arg', 'arg'], {cacheId: 'foobar', cachePath: '/'})
// -> '/foobar/06f254...'
```
Since memoize-fs is using JSON for serialization, __you should know__ how it works around some of its "limitations":

@@ -185,0 +194,0 @@

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