当前位置:网站首页>node. JS architecture optimization: reverse proxy and cache service
node. JS architecture optimization: reverse proxy and cache service
2022-06-25 12:35:00 【Velly_ zheng】
// The following notes are all notes from the learning video , Make it easy to remember
// Video address :https://time.geekbang.org/course/intro/232
app.js file
const app = new (require('koa'))
const cacheRedis = require('redis')('cache')
const backupRedis = require('redis')('backup')
//koa The middle bond of the onion conforms to an onion model
app.use(async(ctx,next) => {
const result = await cacheRedis(ctx.url); // RPC Asynchronous invocation of , from redis Extract a cached file from the
// The request url As key, from redis Take out a copy of the results , Assign a value to result
if(result){ // If there is a result , Directly return the result ; Hit cache
ctx.body = result;
return;
}
await next() // If you miss the cache , Then execute the following middle key
if(ctx.status == 200){ // Judge whether the request result is normal
cacheRedis.set(ctx.url,ctx.body, {expire: 200}); // Write request results to cache , Set expiration time
backupRedis.set(ctx.url,ctx.body, {expire: 200}); // Write the request results to the backup cache , Set expiration time
}
if(ctx.status != 200){
const result = await backupRedis(ctx.url); // From backup redis Take out the results
ctx.status = 200;
ctx.body = result;
}
})
边栏推荐
- PHP numeric array sorting and associative array sorting
- Some fields are ignored in tp6 query
- SDN system method | 9 Access network
- Gradle knowledge points
- ECSHOP whole site custom URL supports directory type
- PHP appends the same elements to a two-dimensional array
- Zhangxiaobai's way of penetration (VIII) - detailed operation steps of SQL injection - Boolean blind injection of blind injection
- ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
- 实现领域驱动设计 - 使用ABP框架 - 系列文章汇总
- The network traceroute command is used to determine the path through which IP packets access the destination address.
猜你喜欢

Zhangxiaobai's way of penetration (V) -- detailed explanation of upload vulnerability and parsing vulnerability

MySQL common interview questions

A set of automated paperless office system (oa+ approval process) source code: with data dictionary

Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation

An easy-to-use seal design tool - (can be converted to ofd file)

揭秘GaussDB(for Redis):全面对比Codis

Découvrir gaussdb (pour redis): une comparaison complète avec Codis

Linear regression of common mathematical modeling models for College Students

Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection

What is the primordial universe
随机推荐
Time series analysis - how to use unit root test (ADF) correctly?
Zhangxiaobai's road to penetration (7) -sql injection detailed operation steps -union joint query injection
Installation and removal of MySQL under Windows
Development with courtesy -- share the source code of the secondary development of the app system of the imitation shopping mall
R language dplyr package filter function filters the data rows in the specified list whose contents in the dataframe data are not (not equal to one of the specified vectors)
PHP numeric array sorting and associative array sorting
R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the lrtest function of epidisplay package to perform multiple model
thinkphp3.2.5 GIF. class. php for php7.4
How to use ARIMA model for prediction?
R language uses ordinal or. The display function obtains the summary statistical information of the ordered logistic regression model (the odds ratio and its confidence interval corresponding to the v
Arm V7 continuous load / store
Full nanny tutorial of Market Research Competition (experience sharing)
Mpai data science platform random forest classification \ explanation of regression parameter adjustment
ECSHOP upload video_ ECSHOP video list, video classification, video related product guide
20. MVVM command binding of WPF
2022 meisai topic C idea sharing + translation
Fun pocket mall -- sharing the development source code of fun pocket app system
[oceanbase] Introduction to oceanbase and its comparison with MySQL
Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation
R language uses the scale function to scale the input data of neural network to the minimum and maximum, scale the data to between 0 and 1, and divide the data set into training set and test set