page_cache.js
2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
*
* @author: chenfeng<feng.chen@yoho.cn>
* @date: 16/10/13
*/
'use strict';
import Router from 'koa-router';
import sh from 'shelljs';
import {
PageCache
} from '../../models';
const r = new Router();
const pageCahe = {
async query(ctx) {
let servers = await PageCache.findAll();
let awsCount = 0;
let awsList = '';
let qCloudCount = 0;
let qCloudList = '';
servers.forEach((server) => {
if (server.server === 'AWS') {
awsCount++;
awsList += server.host + ',';
} else if (server.server === 'qCloud') {
qCloudCount++;
qCloudList += server.host + ',';
}
});
let data = {
storeList: [{
tableName: 'ngx_cache_pc',
name: 'PC'
}, {
tableName: 'ngx_cache_wap',
name: 'Wap'
}],
serverList: [{
name: 'AWS',
value: 'AWS',
list: awsList,
count: awsCount
}, {
name: 'qCloud',
value: 'qCloud',
list: qCloudList,
count: qCloudCount
}],
count: 0
};
await ctx.render('action/page_cache', data);
},
async clear(ctx) {
let queryUris = ctx.request.body.query_uri;
let storeTableName = ctx.request.body.table_name;
let serverType = ctx.request.body.server;
let servers = serverType.split(',').filter(server => server);
if (queryUris && storeTableName && servers.length) {
PageCache.removeCache(queryUris, storeTableName, servers);
}
return ctx.body = {
code: 200
};
},
async clearAll(ctx) {
let storeTableName = ctx.request.body.table_name;
let serverType = ctx.request.body.server;
let servers = serverType.split(',').filter(server => server);
if (storeTableName && servers.length) {
PageCache.removeAllCache(storeTableName, servers);
}
return ctx.body = {
code: 200
};
}
}
r.get('/query', pageCahe.query);
r.post('/clear', pageCahe.clear);
r.post('/clear/all', pageCahe.clearAll);
export default r;