function cache
npm install nq-cacheNQ-CACHE
> function cache





Install npm package
``bash`
npm install nq-cache
Use pureFuncMemoryCache
add.js
`javascript
import { pureFuncMemoryCache } from 'nq-cache'
export function add (a, b) {
return a + b
}
export const addCache = pureFuncMemoryCache(add)
`
app.js
`javascript`
import { addCache as add } from './add'
add(1, 2) // execute and cache the result
add(1, 2) // Get results directly from the cache
use promiseMemoryCache
request.js
`javascript
import { promiseMemoryCache } from 'nq-cache'
export function request (data) {
return new Promise(resolve => {
setTimeout(() => {
resolve(data)
}, 2 * 1000)
})
}
export const requestCache = promiseMemoryCache(request)
`
app.js
`javascript`
import { requestCache as request } from './request'
// execute and cache the result
request({ name: 'bowl' }).then(res => {
// get results directly from the cache
return request({ name: 'bowl' })
})
use promiseSessionStorageCache
request.js
`javascript
import { promiseSessionStorageCache } from 'nq-cache'
export function request (data) {
return new Promise(resolve => {
setTimeout(() => {
resolve(data)
}, 2 * 1000)
})
}
export const requestCache = promiseSessionStorageCache(request, 'request')
`
app.js
`javascript`
import { requestCache as request } from './request'
// execute and cache the result
request({ name: 'bowl' }).then(res => {
// Get results directly from the cache
return request({ name: 'bowl' })
})
#### CDN
Contains only nq-cache
`html`
For more other methods, you can view [example] (https://jsbin.com/baluray/edit?html,js,output)
if the browser does not support Promise or JSON, you should do a polyfill
`html`
- Installation dependencies
`bash`
npm install
- Testing
`bash`
npm test
- Build
`bash`
npm run build
- Flow
`bash`
npm run flow
- ESLint
`bash`
npm run lint
- Update documentation
`bash`
npm run doc
- Run the test page
`bash
npm run build
npm run example
Then open it with a browser
Http://localhost:5000/examples/
`
- Release
`bash``
npm version [new version]
npm run build
npm publish