Flare-k

Modified Caculating Function Speed

1 +describe("Test suite", function () {
2 + it("should be ok", function () {
3 + assert.equal(true, false)
4 + })
5 +})
...\ No newline at end of file ...\ No newline at end of file
1 +class LRUCache{
2 + constructor(capacity){
3 + this.capacity = capacity;
4 + this.map = new Map();
5 + }
6 + get(key){
7 + const value = this.map.get(key);
8 + if(typeof value === "undefined"){
9 + return -1;
10 + }
11 + this.map.delete(key);
12 + this.map.set(key, value);
13 + return value;
14 + }
15 +
16 + put(key, value){
17 + let obj = {};
18 + if(this.map.has(key)){
19 + obj.key = key;
20 + obj.value = this.map.get(key);
21 + this.map.delete(key);
22 + }
23 + else{
24 + obj.key = key;
25 + obj.value = value;
26 + }
27 + this.map.set(key, value);
28 + const keys = this.map.keys();
29 + if(this.map.size > this.capacity){
30 + obj.key = keys.next().value;
31 + obj.value = this.map.get(obj.key);
32 + this.map.delete(obj.key);
33 + }
34 + return obj;
35 + }
36 +}
37 +
38 +module.exports = LRUCache;
...\ No newline at end of file ...\ No newline at end of file
...@@ -9,13 +9,16 @@ import mongoose from "mongoose"; ...@@ -9,13 +9,16 @@ import mongoose from "mongoose";
9 import session from "express-session"; 9 import session from "express-session";
10 import flash from "express-flash"; 10 import flash from "express-flash";
11 import MongoStore from "connect-mongo"; 11 import MongoStore from "connect-mongo";
12 -import { localsMiddleware } from "./middlewares"; 12 +import { localsMiddleware, uploadFile } from "./middlewares";
13 +import File from "./models/File";
13 import routes from "./routes"; 14 import routes from "./routes";
14 import globalRouter from "./routers/globalRouter"; 15 import globalRouter from "./routers/globalRouter";
15 import fileRouter from "./routers/fileRouter"; 16 import fileRouter from "./routers/fileRouter";
16 - 17 +import redis from 'redis';
18 +import JSON from 'JSON';
17 dotenv.config(); 19 dotenv.config();
18 const app = express(); 20 const app = express();
21 +const client = redis.createClient(6379,'127.0.0.1');
19 22
20 const CokieStore = MongoStore(session); 23 const CokieStore = MongoStore(session);
21 24
...@@ -39,6 +42,84 @@ app.use( ...@@ -39,6 +42,84 @@ app.use(
39 app.use(flash()); 42 app.use(flash());
40 app.use(localsMiddleware); 43 app.use(localsMiddleware);
41 app.use(routes.home, globalRouter); 44 app.use(routes.home, globalRouter);
42 -app.use(routes.files, fileRouter); 45 +//app.use(routes.files, fileRouter);
46 +app.use(function(req,res,next){
47 +
48 + req.cache = client;
49 +
50 + next();
51 +
52 +})
53 +
54 +// Caching
55 +app.use(function(req,res,next){
56 + req.cache = client;
57 + next();
58 +})
59 +
60 +app.get(`/files${routes.upload}`, (req, res) =>
61 + res.render("upload", { pageTitle: "Upload" }));
62 +
63 +app.post(`/files${routes.upload}`, uploadFile, (req, res) => {
64 + // multer를 해야 파일이 넘어가는 것이 나타난다.
65 + req.accepts('application/json');
66 + const key = req.body.title;
67 + const value = JSON.stringify(req.body);
68 +
69 + req.cache.set(key, value, (err, data) => {
70 + if(err){
71 + console.log(err);
72 + res.send("error"+err);
73 + return;
74 + }
75 + req.cache.expire(key, 10);
76 + console.log(value);
77 + res.send(value);
78 + });
79 +});
80 +app.get('/files/:title', (req, res, next) => {
81 + const key = req.params.title;
82 + console.log('title : ' + key);
83 +
84 + req.cache.get(key, (err, data) => {
85 + if(err){
86 + console.log(err);
87 + res.send("error : " + err);
88 + return;
89 + }
90 +
91 + const value = JSON.parse(data);
92 + res.json(value);
93 + });
94 +});
95 +
96 +app.get('/view_cache', (req, res) => {
97 + req.cache.get('/files/:title', async (err, data) => {
98 + if(err){
99 + console.log(err);
100 + res.send("error : " + err);
101 + return;
102 + }
103 + if(!data) {
104 + const allData = await File.find({}).sort({ _id: -1 });
105 + const dataArr = JSON.stringify(allData);
106 + req.cache.set('/files/:title', dataArr, (err, data) => {
107 + if(err){
108 + console.log(err);
109 + res.send("error :" + err);
110 + return;
111 + }
112 + req.cache.expire('/files/:title', 10);
113 + res.send(dataArr)
114 + })
115 + }
116 + else {
117 + res.send(data)
118 + }
119 + });
120 +});
121 +
122 +
123 +
43 124
44 export default app; // 파일을 불러올때 app object를 준다는 의미. 125 export default app; // 파일을 불러올때 app object를 준다는 의미.
......
1 /* eslint-disable no-console */ 1 /* eslint-disable no-console */
2 import routes from "../routes"; 2 import routes from "../routes";
3 import File from "../models/File"; 3 import File from "../models/File";
4 +
4 const createCsvWriter = require('csv-writer').createObjectCsvWriter; 5 const createCsvWriter = require('csv-writer').createObjectCsvWriter;
5 const csvInsertWriter = createCsvWriter({ 6 const csvInsertWriter = createCsvWriter({
6 path: 'insertOutput.csv', 7 path: 'insertOutput.csv',
...@@ -23,24 +24,31 @@ export const home = async (req, res) => { ...@@ -23,24 +24,31 @@ export const home = async (req, res) => {
23 res.render("home", { pageTitle: "Home", files: [] }); 24 res.render("home", { pageTitle: "Home", files: [] });
24 } 25 }
25 }; 26 };
26 -const searchTime = new Array(); 27 +// const searchTime = new Array();
27 export const search = async (req, res) => { 28 export const search = async (req, res) => {
28 - const startTime = new Date().getTime(); 29 + console.log(req);
30 + // const startTime = new Date().getTime();
29 const { 31 const {
30 query: { term: searchingBy }, 32 query: { term: searchingBy },
31 } = req; // == const searchingBy = req.query.term; 33 } = req; // == const searchingBy = req.query.term;
32 let files = []; 34 let files = [];
33 try { 35 try {
34 files = await File.find({ 36 files = await File.find({
35 - title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함. 37 + title: { $regex: searchingBy, $options: "i" }, // i를 옵션으로 추가하면 insensitive.. 대소문자 구분 안함.
36 }); 38 });
39 + /*
37 const endTime = new Date().getTime(); // SELECT의 경우 파일 시간 측정 40 const endTime = new Date().getTime(); // SELECT의 경우 파일 시간 측정
38 searchTime.push({ms: endTime - startTime}); 41 searchTime.push({ms: endTime - startTime});
39 - if (searchTime.length === 3){ 42 + if (searchTime.length === 50){
40 csvSelectWriter 43 csvSelectWriter
41 .writeRecords(searchTime) 44 .writeRecords(searchTime)
42 .then(() => console.log("The CSV file was written successfully~")); 45 .then(() => console.log("The CSV file was written successfully~"));
43 } 46 }
47 +
48 + for (var i = 0; i < searchTime.length; i++){
49 + console.log(i+1 + "번째 속도: " + Object.values(searchTime[i]) + "ms");
50 + }
51 + */
44 } catch (error) { 52 } catch (error) {
45 console.log(error); 53 console.log(error);
46 } 54 }
...@@ -54,7 +62,7 @@ export const getUpload = (req, res) => ...@@ -54,7 +62,7 @@ export const getUpload = (req, res) =>
54 62
55 const insertTime = new Array(); 63 const insertTime = new Array();
56 export const postUpload = async (req, res) => { 64 export const postUpload = async (req, res) => {
57 - const startTime = new Date().getTime(); 65 + // const startTime = new Date().getTime();
58 // multer를 해야 파일이 넘어가는 것이 나타난다. 66 // multer를 해야 파일이 넘어가는 것이 나타난다.
59 const { 67 const {
60 body: { title }, 68 body: { title },
...@@ -66,14 +74,20 @@ export const postUpload = async (req, res) => { ...@@ -66,14 +74,20 @@ export const postUpload = async (req, res) => {
66 title, 74 title,
67 // 여기있는 fileUrl, title은 fileDB의 속성이다. 75 // 여기있는 fileUrl, title은 fileDB의 속성이다.
68 }); 76 });
69 - console.log(newFile); 77 + // console.log(newFile);
78 + /*
70 const endTime = new Date().getTime(); // INSERT의 경우 파일 시간 측정 79 const endTime = new Date().getTime(); // INSERT의 경우 파일 시간 측정
71 insertTime.push({ms: endTime - startTime}); 80 insertTime.push({ms: endTime - startTime});
72 - if (insertTime.length === 3){ 81 + if (insertTime.length === 50){
73 csvInsertWriter 82 csvInsertWriter
74 .writeRecords(insertTime) 83 .writeRecords(insertTime)
75 .then(() => console.log("The CSV file was written successfully~")); 84 .then(() => console.log("The CSV file was written successfully~"));
76 } 85 }
86 +
87 + for (var i = 0; i < insertTime.length; i++){
88 + console.log(i+1 + "번째 속도: " + Object.values(insertTime[i]) + "ms");
89 + }
90 + */
77 res.redirect(routes.home); 91 res.redirect(routes.home);
78 }; 92 };
79 93
......
...@@ -2,6 +2,7 @@ dotenv.config(); ...@@ -2,6 +2,7 @@ dotenv.config();
2 import dotenv from "dotenv"; 2 import dotenv from "dotenv";
3 import app from "./app"; // app.js에서 export default app했기 때문에 불러올 수 있다. 3 import app from "./app"; // app.js에서 export default app했기 때문에 불러올 수 있다.
4 import "./db"; 4 import "./db";
5 +import "./test/lruCache.spec";
5 import "./models/File"; 6 import "./models/File";
6 7
7 const PORT = process.env.PORT || 80; 8 const PORT = process.env.PORT || 80;
......
1 +time
2 +146
3 +11
4 +5
5 +5
6 +8
7 +9
8 +79
9 +11
10 +2
11 +154
12 +27
13 +10
14 +9
15 +10
16 +53
17 +8
18 +9
19 +4
20 +8
21 +50
22 +5
23 +10
24 +10
25 +9
26 +9
27 +16
28 +3
29 +3
30 +31
31 +29
32 +4
33 +3
34 +3
35 +5
36 +3
37 +3
38 +3
39 +2
40 +12
41 +49
42 +3
43 +4
44 +3
45 +4
46 +60
47 +3
48 +3
49 +3
50 +4
51 +70
...@@ -18,8 +18,8 @@ var LRU = require("lru-cache") ...@@ -18,8 +18,8 @@ var LRU = require("lru-cache")
18 , length: function (n, key) { return n * 2 + key.length } 18 , length: function (n, key) { return n * 2 + key.length }
19 , dispose: function (key, n) { n.close() } 19 , dispose: function (key, n) { n.close() }
20 , maxAge: 1000 * 60 * 60 } 20 , maxAge: 1000 * 60 * 60 }
21 - , cache = LRU(options) 21 + , cache = new LRU(options)
22 - , otherCache = LRU(50) // sets just the max size 22 + , otherCache = new LRU(50) // sets just the max size
23 23
24 cache.set("key", "value") 24 cache.set("key", "value")
25 cache.get("key") // "value" 25 cache.get("key") // "value"
...@@ -49,10 +49,13 @@ away. ...@@ -49,10 +49,13 @@ away.
49 * `max` The maximum size of the cache, checked by applying the length 49 * `max` The maximum size of the cache, checked by applying the length
50 function to all values in the cache. Not setting this is kind of 50 function to all values in the cache. Not setting this is kind of
51 silly, since that's the whole purpose of this lib, but it defaults 51 silly, since that's the whole purpose of this lib, but it defaults
52 - to `Infinity`. 52 + to `Infinity`. Setting it to a non-number or negative number will
53 + throw a `TypeError`. Setting it to 0 makes it be `Infinity`.
53 * `maxAge` Maximum age in ms. Items are not pro-actively pruned out 54 * `maxAge` Maximum age in ms. Items are not pro-actively pruned out
54 as they age, but if you try to get an item that is too old, it'll 55 as they age, but if you try to get an item that is too old, it'll
55 drop it and return undefined instead of giving it to you. 56 drop it and return undefined instead of giving it to you.
57 + Setting this to a negative value will make everything seem old!
58 + Setting it to a non-number will throw a `TypeError`.
56 * `length` Function that is used to calculate the length of stored 59 * `length` Function that is used to calculate the length of stored
57 items. If you're storing strings or buffers, then you probably want 60 items. If you're storing strings or buffers, then you probably want
58 to do something like `function(n, key){return n.length}`. The default is 61 to do something like `function(n, key){return n.length}`. The default is
...@@ -76,6 +79,11 @@ away. ...@@ -76,6 +79,11 @@ away.
76 it'll be called whenever a `set()` operation overwrites an existing 79 it'll be called whenever a `set()` operation overwrites an existing
77 key. If you set this option, `dispose()` will only be called when a 80 key. If you set this option, `dispose()` will only be called when a
78 key falls out of the cache, not when it is overwritten. 81 key falls out of the cache, not when it is overwritten.
82 +* `updateAgeOnGet` When using time-expiring entries with `maxAge`,
83 + setting this to `true` will make each item's effective time update
84 + to the current time whenever it is retrieved from cache, causing it
85 + to not expire. (It can still fall out of cache based on recency of
86 + use, of course.)
79 87
80 ## API 88 ## API
81 89
......
This diff is collapsed. Click to expand it.
1 { 1 {
2 - "_from": "lru-cache@^4.0.1", 2 + "_from": "lru-cache",
3 - "_id": "lru-cache@4.1.5", 3 + "_id": "lru-cache@6.0.0",
4 "_inBundle": false, 4 "_inBundle": false,
5 - "_integrity": "sha512-sWZlbEP2OsHNkXrMl5GYk/jKk70MBng6UU4YI/qGDYbgf6YbP4EvmqISbXCoJiRKs+1bSpFHVgQxvJ17F2li5g==", 5 + "_integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==",
6 "_location": "/lru-cache", 6 "_location": "/lru-cache",
7 "_phantomChildren": {}, 7 "_phantomChildren": {},
8 "_requested": { 8 "_requested": {
9 - "type": "range", 9 + "type": "tag",
10 "registry": true, 10 "registry": true,
11 - "raw": "lru-cache@^4.0.1", 11 + "raw": "lru-cache",
12 "name": "lru-cache", 12 "name": "lru-cache",
13 "escapedName": "lru-cache", 13 "escapedName": "lru-cache",
14 - "rawSpec": "^4.0.1", 14 + "rawSpec": "",
15 "saveSpec": null, 15 "saveSpec": null,
16 - "fetchSpec": "^4.0.1" 16 + "fetchSpec": "latest"
17 }, 17 },
18 "_requiredBy": [ 18 "_requiredBy": [
19 - "/cross-spawn" 19 + "#USER",
20 + "/"
20 ], 21 ],
21 - "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.5.tgz", 22 + "_resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
22 - "_shasum": "8bbe50ea85bed59bc9e33dcab8235ee9bcf443cd", 23 + "_shasum": "6d6fe6570ebd96aaf90fcad1dafa3b2566db3a94",
23 - "_spec": "lru-cache@^4.0.1", 24 + "_spec": "lru-cache",
24 - "_where": "/Users/noblyan/Desktop/4_2/캡스톤디자인II/2017110267/Project/node_modules/cross-spawn", 25 + "_where": "/Users/noblyan/Desktop/4_2/캡스톤디자인II/2017110267/Project",
25 "author": { 26 "author": {
26 "name": "Isaac Z. Schlueter", 27 "name": "Isaac Z. Schlueter",
27 "email": "i@izs.me" 28 "email": "i@izs.me"
...@@ -31,15 +32,16 @@ ...@@ -31,15 +32,16 @@
31 }, 32 },
32 "bundleDependencies": false, 33 "bundleDependencies": false,
33 "dependencies": { 34 "dependencies": {
34 - "pseudomap": "^1.0.2", 35 + "yallist": "^4.0.0"
35 - "yallist": "^2.1.2"
36 }, 36 },
37 "deprecated": false, 37 "deprecated": false,
38 "description": "A cache object that deletes the least-recently-used items.", 38 "description": "A cache object that deletes the least-recently-used items.",
39 "devDependencies": { 39 "devDependencies": {
40 "benchmark": "^2.1.4", 40 "benchmark": "^2.1.4",
41 - "standard": "^12.0.1", 41 + "tap": "^14.10.7"
42 - "tap": "^12.1.0" 42 + },
43 + "engines": {
44 + "node": ">=10"
43 }, 45 },
44 "files": [ 46 "files": [
45 "index.js" 47 "index.js"
...@@ -58,14 +60,11 @@ ...@@ -58,14 +60,11 @@
58 "url": "git://github.com/isaacs/node-lru-cache.git" 60 "url": "git://github.com/isaacs/node-lru-cache.git"
59 }, 61 },
60 "scripts": { 62 "scripts": {
61 - "coveragerport": "tap --coverage-report=html", 63 + "postversion": "npm publish",
62 - "lintfix": "standard --fix test/*.js index.js", 64 + "prepublishOnly": "git push origin --follow-tags",
63 - "postpublish": "git push origin --all; git push origin --tags",
64 - "posttest": "standard test/*.js index.js",
65 - "postversion": "npm publish --tag=legacy",
66 "preversion": "npm test", 65 "preversion": "npm test",
67 - "snap": "TAP_SNAPSHOT=1 tap test/*.js -J", 66 + "snap": "tap",
68 - "test": "tap test/*.js --100 -J" 67 + "test": "tap"
69 }, 68 },
70 - "version": "4.1.5" 69 + "version": "6.0.0"
71 } 70 }
......
1 -var Yallist = require('./yallist.js') 1 +'use strict'
2 - 2 +module.exports = function (Yallist) {
3 -Yallist.prototype[Symbol.iterator] = function* () { 3 + Yallist.prototype[Symbol.iterator] = function* () {
4 - for (let walker = this.head; walker; walker = walker.next) { 4 + for (let walker = this.head; walker; walker = walker.next) {
5 - yield walker.value 5 + yield walker.value
6 + }
6 } 7 }
7 } 8 }
......
1 { 1 {
2 - "_from": "yallist@^2.1.2", 2 + "_from": "yallist@^4.0.0",
3 - "_id": "yallist@2.1.2", 3 + "_id": "yallist@4.0.0",
4 "_inBundle": false, 4 "_inBundle": false,
5 - "_integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=", 5 + "_integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
6 "_location": "/yallist", 6 "_location": "/yallist",
7 "_phantomChildren": {}, 7 "_phantomChildren": {},
8 "_requested": { 8 "_requested": {
9 "type": "range", 9 "type": "range",
10 "registry": true, 10 "registry": true,
11 - "raw": "yallist@^2.1.2", 11 + "raw": "yallist@^4.0.0",
12 "name": "yallist", 12 "name": "yallist",
13 "escapedName": "yallist", 13 "escapedName": "yallist",
14 - "rawSpec": "^2.1.2", 14 + "rawSpec": "^4.0.0",
15 "saveSpec": null, 15 "saveSpec": null,
16 - "fetchSpec": "^2.1.2" 16 + "fetchSpec": "^4.0.0"
17 }, 17 },
18 "_requiredBy": [ 18 "_requiredBy": [
19 "/lru-cache" 19 "/lru-cache"
20 ], 20 ],
21 - "_resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz", 21 + "_resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
22 - "_shasum": "1c11f9218f076089a47dd512f93c6699a6a81d52", 22 + "_shasum": "9bb92790d9c0effec63be73519e11a35019a3a72",
23 - "_spec": "yallist@^2.1.2", 23 + "_spec": "yallist@^4.0.0",
24 "_where": "/Users/noblyan/Desktop/4_2/캡스톤디자인II/2017110267/Project/node_modules/lru-cache", 24 "_where": "/Users/noblyan/Desktop/4_2/캡스톤디자인II/2017110267/Project/node_modules/lru-cache",
25 "author": { 25 "author": {
26 "name": "Isaac Z. Schlueter", 26 "name": "Isaac Z. Schlueter",
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
35 "deprecated": false, 35 "deprecated": false,
36 "description": "Yet Another Linked List", 36 "description": "Yet Another Linked List",
37 "devDependencies": { 37 "devDependencies": {
38 - "tap": "^10.3.0" 38 + "tap": "^12.1.0"
39 }, 39 },
40 "directories": { 40 "directories": {
41 "test": "test" 41 "test": "test"
...@@ -58,5 +58,5 @@ ...@@ -58,5 +58,5 @@
58 "preversion": "npm test", 58 "preversion": "npm test",
59 "test": "tap test/*.js --100" 59 "test": "tap test/*.js --100"
60 }, 60 },
61 - "version": "2.1.2" 61 + "version": "4.0.0"
62 } 62 }
......
1 +'use strict'
1 module.exports = Yallist 2 module.exports = Yallist
2 3
3 Yallist.Node = Node 4 Yallist.Node = Node
...@@ -53,6 +54,8 @@ Yallist.prototype.removeNode = function (node) { ...@@ -53,6 +54,8 @@ Yallist.prototype.removeNode = function (node) {
53 node.next = null 54 node.next = null
54 node.prev = null 55 node.prev = null
55 node.list = null 56 node.list = null
57 +
58 + return next
56 } 59 }
57 60
58 Yallist.prototype.unshiftNode = function (node) { 61 Yallist.prototype.unshiftNode = function (node) {
...@@ -317,6 +320,37 @@ Yallist.prototype.sliceReverse = function (from, to) { ...@@ -317,6 +320,37 @@ Yallist.prototype.sliceReverse = function (from, to) {
317 return ret 320 return ret
318 } 321 }
319 322
323 +Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
324 + if (start > this.length) {
325 + start = this.length - 1
326 + }
327 + if (start < 0) {
328 + start = this.length + start;
329 + }
330 +
331 + for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
332 + walker = walker.next
333 + }
334 +
335 + var ret = []
336 + for (var i = 0; walker && i < deleteCount; i++) {
337 + ret.push(walker.value)
338 + walker = this.removeNode(walker)
339 + }
340 + if (walker === null) {
341 + walker = this.tail
342 + }
343 +
344 + if (walker !== this.head && walker !== this.tail) {
345 + walker = walker.prev
346 + }
347 +
348 + for (var i = 0; i < nodes.length; i++) {
349 + walker = insert(this, walker, nodes[i])
350 + }
351 + return ret;
352 +}
353 +
320 Yallist.prototype.reverse = function () { 354 Yallist.prototype.reverse = function () {
321 var head = this.head 355 var head = this.head
322 var tail = this.tail 356 var tail = this.tail
...@@ -330,6 +364,23 @@ Yallist.prototype.reverse = function () { ...@@ -330,6 +364,23 @@ Yallist.prototype.reverse = function () {
330 return this 364 return this
331 } 365 }
332 366
367 +function insert (self, node, value) {
368 + var inserted = node === self.head ?
369 + new Node(value, null, node, self) :
370 + new Node(value, node, node.next, self)
371 +
372 + if (inserted.next === null) {
373 + self.tail = inserted
374 + }
375 + if (inserted.prev === null) {
376 + self.head = inserted
377 + }
378 +
379 + self.length++
380 +
381 + return inserted
382 +}
383 +
333 function push (self, item) { 384 function push (self, item) {
334 self.tail = new Node(item, self.tail, null, self) 385 self.tail = new Node(item, self.tail, null, self)
335 if (!self.head) { 386 if (!self.head) {
...@@ -368,3 +419,8 @@ function Node (value, prev, next, list) { ...@@ -368,3 +419,8 @@ function Node (value, prev, next, list) {
368 this.next = null 419 this.next = null
369 } 420 }
370 } 421 }
422 +
423 +try {
424 + // add if support for Symbol.iterator is present
425 + require('./iterator.js')(Yallist)
426 +} catch (er) {}
......
This diff is collapsed. Click to expand it.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
7 "dev:server": "nodemon --exec babel-node init.js --delay 2 --ignore '.scss' --ignore 'static'", 7 "dev:server": "nodemon --exec babel-node init.js --delay 2 --ignore '.scss' --ignore 'static'",
8 "dev:assets": "WEBPACK_ENV=development webpack -w", 8 "dev:assets": "WEBPACK_ENV=development webpack -w",
9 "build:assets": "WEBPACK_ENV=production webpack", 9 "build:assets": "WEBPACK_ENV=production webpack",
10 - "tunnel": "ngrok http 80" 10 + "test": "mocha"
11 }, 11 },
12 "repository": { 12 "repository": {
13 "type": "git", 13 "type": "git",
...@@ -21,11 +21,13 @@ ...@@ -21,11 +21,13 @@
21 "@babel/node": "^7.8.7", 21 "@babel/node": "^7.8.7",
22 "@babel/polyfill": "^7.10.1", 22 "@babel/polyfill": "^7.10.1",
23 "@babel/preset-env": "^7.9.6", 23 "@babel/preset-env": "^7.9.6",
24 + "JSON": "^1.0.0",
24 "autoprefixer": "^9.8.0", 25 "autoprefixer": "^9.8.0",
25 "aws-sdk": "^2.702.0", 26 "aws-sdk": "^2.702.0",
26 "axios": "^0.19.2", 27 "axios": "^0.19.2",
27 "babel-loader": "^8.1.0", 28 "babel-loader": "^8.1.0",
28 "body-parser": "^1.19.0", 29 "body-parser": "^1.19.0",
30 + "chai": "^4.2.0",
29 "connect-mongo": "^3.2.0", 31 "connect-mongo": "^3.2.0",
30 "cookie-parser": "^1.4.5", 32 "cookie-parser": "^1.4.5",
31 "css-loader": "^3.5.3", 33 "css-loader": "^3.5.3",
...@@ -37,6 +39,7 @@ ...@@ -37,6 +39,7 @@
37 "extract-text-webpack-plugin": "^4.0.0-beta.0", 39 "extract-text-webpack-plugin": "^4.0.0-beta.0",
38 "get-blob-duration": "^1.1.1", 40 "get-blob-duration": "^1.1.1",
39 "helmet": "^3.22.0", 41 "helmet": "^3.22.0",
42 + "lru-cache": "^6.0.0",
40 "mongoose": "^5.9.15", 43 "mongoose": "^5.9.15",
41 "morgan": "^1.10.0", 44 "morgan": "^1.10.0",
42 "multer": "^1.4.2", 45 "multer": "^1.4.2",
...@@ -52,6 +55,7 @@ ...@@ -52,6 +55,7 @@
52 "perf_hooks": "0.0.1", 55 "perf_hooks": "0.0.1",
53 "postcss-loader": "^3.0.0", 56 "postcss-loader": "^3.0.0",
54 "pug": "^2.0.4", 57 "pug": "^2.0.4",
58 + "redis": "^3.0.2",
55 "sass-loader": "^8.0.2", 59 "sass-loader": "^8.0.2",
56 "webpack": "^4.43.0", 60 "webpack": "^4.43.0",
57 "webpack-cli": "^3.3.11" 61 "webpack-cli": "^3.3.11"
...@@ -62,7 +66,10 @@ ...@@ -62,7 +66,10 @@
62 "eslint-config-prettier": "^6.11.0", 66 "eslint-config-prettier": "^6.11.0",
63 "eslint-plugin-import": "^2.21.1", 67 "eslint-plugin-import": "^2.21.1",
64 "eslint-plugin-prettier": "^3.1.3", 68 "eslint-plugin-prettier": "^3.1.3",
69 + "mocha": "^8.2.1",
70 + "loadtest": "*",
65 "nodemon": "^2.0.4", 71 "nodemon": "^2.0.4",
66 - "prettier": "^2.0.5" 72 + "prettier": "^2.0.5",
73 + "supertest": "^6.0.1"
67 } 74 }
68 } 75 }
......
1 +time
2 +24
3 +4
4 +6
5 +6
6 +3
7 +3
8 +3
9 +3
10 +3
11 +3
12 +2
13 +2
14 +3
15 +2
16 +3
17 +2
18 +2
19 +2
20 +2
21 +11
22 +7
23 +5
24 +3
25 +2
26 +2
27 +2
28 +2
29 +3
30 +2
31 +2
32 +2
33 +2
34 +2
35 +2
36 +2
37 +6
38 +3
39 +2
40 +13
41 +39
42 +3
43 +2
44 +2
45 +2
46 +2
47 +2
48 +3
49 +2
50 +1
51 +3
1 +/*
2 +const { expect } = require('chai');
3 +const LRU = require('lru-cache');
4 +
5 +const MAX = 3;
6 +
7 +const options = {
8 + max: MAX,
9 + maxAge: 1900,
10 + length(n, key) { return 1},
11 +};
12 +
13 +describe('LRU Cache Test', () => {
14 + before( () => {
15 + lruCache = new LRU(options);
16 + // 데이터들을 최대로 cache!
17 + lruCache.set(1, 'SampleData1');
18 + lruCache.set(2, 'SampleData2');
19 + lruCache.set(3, 'SampleData3');
20 + });
21 +
22 + it('LRU algorithm Test', () => {
23 + // Happy3을 key로 가지는 데이터를 가장 사용 안함
24 + lruCache.keys().forEach( k => {
25 + for(let i = 0; i <= MAX - k; i++) {
26 + console.log("########", k, lruCache.get(k));
27 + }
28 + });
29 +
30 + // 새로운 데이터 cache!
31 + lruCache.set(4, 'SampleData4');
32 +
33 + //LRU 알고리즘에 의해 key가 3인 데이터가 삭제되어야함
34 + expect(lruCache.has(1)).to.be.equal(true);
35 + expect(lruCache.has(2)).to.be.equal(true);
36 + expect(lruCache.has(3)).to.be.equal(false);
37 + expect(lruCache.has(4)).to.be.equal(true);
38 + });
39 +
40 + it('dump & load Test', () => {
41 + //dump
42 + let cacheEntriesArray = lruCache.dump();
43 + lruCache.reset();
44 + expect(lruCache.itemCount).to.be.equal(0);
45 +
46 + //load
47 + lruCache.load(cacheEntriesArray);
48 + expect(lruCache.itemCount).to.be.equal(3);
49 + });
50 +
51 +
52 + it('Expire time Test', done => {
53 + //maxAge 시간 후엔 데이터 모두 만료되어야함
54 + setTimeout(() => {
55 + cache.prune();
56 + expect(lruCache.itemCount).to.be.equal(0);
57 + done();
58 + }, 1900);
59 + });
60 +});*/
...\ No newline at end of file ...\ No newline at end of file
...@@ -7,4 +7,5 @@ block content ...@@ -7,4 +7,5 @@ block content
7 label(for="file") File 7 label(for="file") File
8 input(type="file", id="file", name="file", required=true) 8 input(type="file", id="file", name="file", required=true)
9 input(type="text", placeholder="Title", name="title", required=true) 9 input(type="text", placeholder="Title", name="title", required=true)
10 + input(type="text", placeholder="Description", name="description", required=true)
10 input(type="submit", value="Upload File") 11 input(type="submit", value="Upload File")
...\ No newline at end of file ...\ No newline at end of file
......
1 +time
2 +37
3 +11
4 +6
5 +13
6 +4
7 +9
8 +9
9 +11
10 +3
11 +3
12 +3
13 +9
14 +12
15 +9
16 +5
17 +3
18 +2
19 +3
20 +8
21 +4
22 +2
23 +2
24 +5
25 +4
26 +2
27 +3
28 +3
29 +3
30 +3
31 +3
32 +6
33 +2
34 +2
35 +3
36 +2
37 +2
38 +7
39 +3
40 +2
41 +3
42 +3
43 +2
44 +5
45 +8
46 +6
47 +3
48 +3
49 +2
50 +2
51 +6
1 +time
2 +18
3 +5
4 +3
5 +3
6 +4
7 +2
8 +3
9 +3
10 +2
11 +3
12 +2
13 +2
14 +2
15 +2
16 +3
17 +2
18 +2
19 +2
20 +3
21 +2
22 +2
23 +2
24 +2
25 +2
26 +2
27 +2
28 +3
29 +4
30 +2
31 +3
32 +2
33 +2
34 +3
35 +2
36 +3
37 +2
38 +2
39 +2
40 +1
41 +2
42 +2
43 +1
44 +2
45 +2
46 +2
47 +3
48 +2
49 +3
50 +3
51 +3
1 +time
2 +146
3 +11
4 +5
5 +5
6 +8
7 +9
8 +79
9 +11
10 +2
11 +154
12 +27
13 +10
14 +9
15 +10
16 +53
17 +8
18 +9
19 +4
20 +8
21 +50
22 +5
23 +10
24 +10
25 +9
26 +9
27 +16
28 +3
29 +3
30 +31
31 +29
32 +4
33 +3
34 +3
35 +5
36 +3
37 +3
38 +3
39 +2
40 +12
41 +49
42 +3
43 +4
44 +3
45 +4
46 +60
47 +3
48 +3
49 +3
50 +4
51 +70
1 +time
2 +24
3 +4
4 +6
5 +6
6 +3
7 +3
8 +3
9 +3
10 +3
11 +3
12 +2
13 +2
14 +3
15 +2
16 +3
17 +2
18 +2
19 +2
20 +2
21 +11
22 +7
23 +5
24 +3
25 +2
26 +2
27 +2
28 +2
29 +3
30 +2
31 +2
32 +2
33 +2
34 +2
35 +2
36 +2
37 +6
38 +3
39 +2
40 +13
41 +39
42 +3
43 +2
44 +2
45 +2
46 +2
47 +2
48 +3
49 +2
50 +1
51 +3