Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
NQ-CACHE
函数缓存
安装npm包
npm install nq-cache
使用 pureFuncMemoryCache
add.js
import { pureFuncMemoryCache } from 'nq-cache'
export function add (a, b) {
return a + b
}
export const addCache = pureFuncMemoryCache(add)
app.js
import { addCache as add } from './add'
add(1, 2) // 执行,并把结果缓存
add(1, 2) // 直接从缓存中获取结果
使用 promiseMemoryCache
request.js
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
import { requestCache as request } from './request'
// 执行,并把结果缓存
request({ name: 'bowl' }).then(res => {
// 直接从缓存中获取结果
return request({ name: 'bowl' })
})
使用 promiseSessionStorageCache
request.js
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
import { requestCache as request } from './request'
// 执行,并把结果缓存
request({ name: 'bowl' }).then(res => {
// 直接从缓存中获取结果
return request({ name: 'bowl' })
})
仅包含 nq-cache
<!-- 使用最新版本 -->
<script src="https://unpkg.com/nq-cache@latest"></script>
<!-- 或指定某一个版本 -->
<script src="https://unpkg.com/nq-cache@0.0.2"></script>
<script>
function add (a, b) {
return a + b
}
addCache = cache.pureFuncMemoryCache(add)
addCache(1, 2) // 执行,并把结果缓存
addCache(1, 2) // 直接从缓存中获取结果
</script>
其他更多的方法,可以查看例子
提示,如果浏览器不支持 Promise 或者 JSON,你应该进行 polyfill
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/promise-polyfill@8/dist/polyfill.min.js"></script>
<!--[if lt IE 8]>
<script type="text/javascript" src="https://cdn.bootcss.com/json2/20160511/json2.min.js"></script>
<![endif]-->
npm install
npm test
npm run build
Flow
npm run flow
ESLint
npm run lint
npm run doc
FAQs
function cache
The npm package nq-cache receives a total of 3 weekly downloads. As such, nq-cache popularity was classified as not popular.
We found that nq-cache demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.