Skip to content

Commit 9237544

Browse files
committed
refactor: use own cache
1 parent ff1e8e6 commit 9237544

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

library.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
'use strict';
55

6-
const winston = require.main.require('winston');
76
const nconf = require.main.require('nconf');
87
const dns = require('dns');
98

@@ -12,7 +11,12 @@ const { load } = require('cheerio');
1211
const { isURL } = require('validator');
1312

1413
const meta = require.main.require('./src/meta');
15-
const cache = require.main.require('./src/cache');
14+
const cacheCreate = require.main.require('./src/cacheCreate');
15+
const cache = cacheCreate({
16+
name: 'link-preview',
17+
max: 10000,
18+
ttl: 0,
19+
});
1620
const posts = require.main.require('./src/posts');
1721
const postsCache = require.main.require('./src/posts/cache');
1822
const websockets = require.main.require('./src/socket.io');
@@ -21,7 +25,7 @@ const controllers = require('./lib/controllers');
2125

2226
const routeHelpers = require.main.require('./src/routes/helpers');
2327

24-
const plugin = {};
28+
const plugin = module.exports;
2529

2630
plugin.init = async (params) => {
2731
const { router /* , middleware , controllers */ } = params;
@@ -393,4 +397,8 @@ plugin.addAdminNavigation = (header) => {
393397
return header;
394398
};
395399

396-
module.exports = plugin;
400+
plugin.filterAdminCacheGet = function (caches) {
401+
caches['link-preview'] = cache;
402+
return caches;
403+
};
404+

plugin.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
{ "hook": "filter:parse.post", "method": "onParse" },
1010
{ "hook": "filter:parse.raw", "method": "onParse" },
1111
{ "hook": "action:post.save", "method": "onPost" },
12-
{ "hook": "action:post.edit", "method": "onPost" }
12+
{ "hook": "action:post.edit", "method": "onPost" },
13+
{ "hook": "filter:admin.cache.get", "method": "filterAdminCacheGet" }
1314
],
1415
"scss": [
1516
"static/scss/link-preview.scss"

0 commit comments

Comments
 (0)