
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
egg-easy-process-cache
Advanced tools
[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down
[![build status][travis-image]][travis-url]
[![David deps][david-image]][david-url]
egg-easy-process-cache 版本 | egg 2.x |
---|---|
2.x | 😁 |
0.x | ❌ |
// config/plugin.js
exports.easyProcessCache = {
enable: true,
package: 'egg-easy-process-cache',
};
在 app.js
中
export default class App {
constructor(app) {
this.app = app;
this.init();
}
async init() {
const { app } = this;
const ctx = await this.app.createAnonymousContext();
app.messenger.on(ctx.getProcessCacheEvent.ALL_WORKER_READY, async () => {
// 监听了 ALL_WORKER_READY 事件,当所有子进程都准备好之后,你可以在这回调进行初始化数据
// 该回调只会随机被某个子进程触发,而不是全部子进程都触发
await ctx.service.qrcode.index.initStoreData();
});
}
}
更新缓存数据
function test() {
// 当你要更新数据的时候,通知给 agent,并把数据带过去就行了
// agent 会再通知全部子进程进行更新
this.ctx.app.messenger.sendToAgent(this.ctx.getProcessCacheEvent.CACHE_COVER, data)
}
config
config.easyProcessCache = {
primaryKey: 'id',
cacheField: [
'id',
'link'
], // 缓存的字段,不传就缓存全部
};
我在上下文添加了两个变量:
function test() {
this.ctx.getProcessCache() // 返回缓存对象
this.ctx.getProcessCacheEvent = {
CACHE_COVER,
CACHE_UPDATE,
CACHE_PUSH,
CACHE_CLEAR,
CACHE_UPDATE_BY_KEY,
WORKER_READY,
ALL_WORKER_READY,
} // getProcessCacheEvent 缓存了各个触发的事件
}
Cache 对象方法
方法名 | 参数 | 返回 | 说明 |
---|---|---|---|
cover | data: Array | - | 覆盖缓存的数据 |
push | data: Object | - | 插入数据 |
removeByKey | val: any | - | 根据该值和 primaryKey 移除对应的对象 |
updateByKey | data: Object | - | 根据 primaryKey 更新对象的值 |
clear | - | - | 清空缓存数据 |
find | (key: string, val: any) | Object | undefined | 根据 key 和值查找对象 |
不建议通过 Cache 对象去更新缓存数据。要修改 Cache 对象的值,要用事件通知 agent 进行更新
预设的 agent 事件
事件名 | 参数 | 说明 |
---|---|---|
CACHE_COVER | data: Array | 通知覆盖缓存数据 |
CACHE_PUSH | data: Object | 通知插入缓存数据 |
CACHE_UPDATE_BY_KEY | data: Object | 通知更新某个缓存数据 |
CACHE_REMOVE_BY_KEY | data: any | 通知移除某个数据 |
CACHE_CLEAR | - | 通知清空缓存数据 |
上面的通知,都是先更新 agent 进程的缓存数据,然后 agent 进程再通知其他子进程进行全覆盖操作
请到 egg issues 异步交流。
FAQs
[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][codecov-image]][codecov-url] [![David deps][david-image]][david-url] [![Known Vulnerabilities][snyk-image]][snyk-url] [![npm download][download-image]][down
The npm package egg-easy-process-cache receives a total of 0 weekly downloads. As such, egg-easy-process-cache popularity was classified as not popular.
We found that egg-easy-process-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.
Security News
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.