mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Perf: adjust cache TTL
This commit is contained in:
parent
10e4b19f40
commit
61b88c5807
@ -100,7 +100,7 @@ export class Cache {
|
||||
if (temporaryBypass) {
|
||||
return fn();
|
||||
}
|
||||
if (ttl === null) {
|
||||
if (ttl == null) {
|
||||
this.del(key);
|
||||
return fn();
|
||||
}
|
||||
@ -108,7 +108,7 @@ export class Cache {
|
||||
const cached = this.get(key);
|
||||
let value: T;
|
||||
if (cached == null) {
|
||||
console.log(picocolors.yellow('[cache] miss'), picocolors.gray(key));
|
||||
console.log(picocolors.yellow('[cache] miss'), picocolors.gray(key), picocolors.gray(`ttl: ${ttl / 60 * 60 * 1000}h`));
|
||||
value = await fn();
|
||||
|
||||
const serializer = 'serializer' in opt ? opt.serializer : identity;
|
||||
@ -136,13 +136,13 @@ const randomInt = (min: number, max: number) => Math.floor(Math.random() * (max
|
||||
|
||||
// Add some randomness to the cache ttl to avoid thundering herd
|
||||
export const TTL = {
|
||||
THREE_HOURS: () => randomInt(2, 4) * 60 * 60 * 1000,
|
||||
TWLVE_HOURS: () => randomInt(9, 14) * 60 * 60 * 1000,
|
||||
THREE_HOURS: () => randomInt(1, 3) * 60 * 60 * 1000,
|
||||
TWLVE_HOURS: () => randomInt(8, 12) * 60 * 60 * 1000,
|
||||
ONE_DAY: () => randomInt(23, 25) * 60 * 60 * 1000,
|
||||
THREE_DAYS: () => randomInt(2, 4) * 24 * 60 * 60 * 1000,
|
||||
ONE_WEEK: () => randomInt(5, 8) * 24 * 60 * 60 * 1000,
|
||||
TWO_WEEKS: () => randomInt(12, 16) * 24 * 60 * 60 * 1000,
|
||||
TEN_DAYS: () => randomInt(9, 11) * 24 * 60 * 60 * 1000
|
||||
THREE_DAYS: () => randomInt(1, 3) * 24 * 60 * 60 * 1000,
|
||||
ONE_WEEK: () => randomInt(5, 7) * 24 * 60 * 60 * 1000,
|
||||
TWO_WEEKS: () => randomInt(10, 14) * 24 * 60 * 60 * 1000,
|
||||
TEN_DAYS: () => randomInt(7, 10) * 24 * 60 * 60 * 1000
|
||||
};
|
||||
|
||||
const separator = '\u0000';
|
||||
|
||||
@ -5,6 +5,7 @@ import * as tldts from 'tldts';
|
||||
import { createTrie } from './trie';
|
||||
import { createCachedGorhillGetDomain } from './cached-tld-parse';
|
||||
import { processLine } from './process-line';
|
||||
import { TTL } from './cache-filesystem';
|
||||
|
||||
const WHITELIST_DOMAIN = new Set([
|
||||
'w3s.link',
|
||||
@ -84,8 +85,8 @@ const BLACK_TLD = new Set([
|
||||
|
||||
export const getPhishingDomains = () => traceAsync('get phishing domains', async () => {
|
||||
const [domainSet, domainSet2, gorhill] = await Promise.all([
|
||||
processHosts('https://curbengh.github.io/phishing-filter/phishing-filter-hosts.txt', true, true),
|
||||
processDomainLists('https://phishing.army/download/phishing_army_blocklist.txt', true),
|
||||
processHosts('https://curbengh.github.io/phishing-filter/phishing-filter-hosts.txt', true, true, TTL.THREE_HOURS()),
|
||||
processDomainLists('https://phishing.army/download/phishing_army_blocklist.txt', true, TTL.THREE_HOURS()),
|
||||
getGorhillPublicSuffixPromise()
|
||||
]);
|
||||
domainSet2.forEach((domain) => domainSet.add(domain));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user