Skip to content

Commit

Permalink
Merge pull request #30 from DeBuXer/ttl
Browse files Browse the repository at this point in the history
Option to override the default cache TTL of 86400 seconds
  • Loading branch information
willnode authored Aug 8, 2024
2 parents 33d5621 + bc480d4 commit 4d3c5dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions HOSTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This guide will walk you through the process of setting up your own instance of
`BLACKLIST_REDIRECT` | The URL to redirect to when a blacklisted host is accessed
`HOME_DOMAIN` | The host to enable `/stat` endpoint
`USE_LOCAL_DNS` | Default is `false`, so the Google DNS is used. Set it to `true` if you want to use the DNS resolver of your own host
`CACHE_EXPIRY_SECONDS` | Option to override the default cache TTL of 86400 seconds (1 day)

If `WHITELIST_HOSTS` is set, `BLACKLIST_HOSTS` is ignored. Both is mutually exclusive.

Expand Down
7 changes: 6 additions & 1 deletion src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import {
*/
let resolveCache = new LRUCache({ max: 10000 });

/**
* @type {int | 86400}
*/
const cacheExpirySeconds = parseInt(process.env.CACHE_EXPIRY_SECONDS, 10) || 86400;

function pruneCache() {
resolveCache = new LRUCache({ max: 10000 });
}
Expand Down Expand Up @@ -71,7 +76,7 @@ async function buildCache(host) {
url,
expand,
blacklisted: isHostBlacklisted(host),
expire: Date.now() + 86400 * 1000,
expire: Date.now() + cacheExpirySeconds * 1000,
httpStatus: parseInt(httpStatus),
};
}
Expand Down

0 comments on commit 4d3c5dc

Please sign in to comment.