
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Library ini akan menyimpan response ke dalam Redis' cache ### Dependency Library ini menggunakan package [**bluebird v3.5.5**](https://www.npmjs.com/package/bluebird) dan [**redis v2.8.0**](https://www.npmjs.com/package/redis). ### Installation ```bas
Library ini akan menyimpan response ke dalam Redis' cache
Library ini menggunakan package bluebird v3.5.5 dan redis v2.8.0.
npm i git+ssh://git@repository.meteor.asia/mtr-platform/libs/redis-cache#v1.1.0
Deklarasikan module library di dalam file app.js
.
const { setRedis } = require('mtr-cache');
const redisHost = env.REDIS_HOST || '127.0.0.1';
const redisPort = Number(env.REDIS_PORT) || '6379';
setRedis(redisHost, redisPort);
Buat sebuah middleware untuk melakukan pengecekan cache,
middleware dapat dibuat secara individu per endpoint
atau dapat dibuat secara global pada app.js
.
Berikut adalah contoh bila dibuat secara individu per endpoint:
const { response } = require('mtr-response');
const { mwCache } = require('mtr-cache');
const { env } = process;
const svc = env.SVC_NAME || 'Meteor';
module.exports = async (req, res, next) => {
const {
'x-forwarded-path': Path, 'x-forwarded-method': Method, 'x-app-key': appKey, 'x-forwarded-authorization': Authorization,
} = req.headers;
const key = `${svc}-svc_p:${(path.split('?')[0])}_m:${Method}_k:${appKey}_a:${Authorization}`;
await mwCache(key)
.then(ok => response(200, ok, res))
.catch(err => response(400, err, res));
};
Berikut adalah contoh penggunaanya:
const { storeCache } = require('mtr-cache');
const svcName = env.SVC_NAME || 'Meteor';
module.exports = async (req, res) => {
const key = `${svcName}-svc_p:${(path.split('?')[0])}_m:${method}_k:${xAppKey}_a:${auth !== undefined ? auth : '-'}`;
const redisVal = 'OK';
const ttl = 15;
await storeCache(key, redisVal, ttl)
.then(() => response(200, { key, redisVal }, res))
.catch(err => response(400, err, res));
};
Seluruh cache dari satu service dapat dibersihkan dengan function purgeCache(keypart)
.
Berikut adalah contoh penggunaannya:
const { response } = require('mtr-response');
const { purgeCache } = require('mtr-cache');
const svcName = env.SVC_NAME || 'Meteor';
module.exports = async (req, res) => {
const replies = await purgeCache(`${svcName}-svc`);
if (replies) response(200, 'Cache purged!', res);
response(400, 'Cache purge failed!', res);
};
FAQs
Library ini akan menyimpan response ke dalam Redis' cache ### Dependency Library ini menggunakan package [**bluebird v3.5.5**](https://www.npmjs.com/package/bluebird) dan [**redis v2.8.0**](https://www.npmjs.com/package/redis). ### Installation ```bas
We found that mtr-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
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.