Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
env var for filesystem cache dir
  • Loading branch information
janoside committed May 21, 2021
1 parent 1da895a commit faef9fb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .env-sample
Expand Up @@ -137,6 +137,12 @@
#BTCEXP_IPSTACK_APIKEY=000000fffffaaaaa
#BTCEXP_MAPBOX_APIKEY=000000fffffaaaaa


# Optional value for a directory for filesystem caching
# Default: ./cache
#BTCEXP_FILESYSTEM_CACHE_DIR=./cache


# Optional analytics
#BTCEXP_PLAUSIBLE_ANALYTICS_DOMAIN=domain.com
#BTCEXP_PLAUSIBLE_ANALYTICS_SCRIPT_URL=https://url-to/plausible.js
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -57,3 +57,6 @@ typings/
# dotenv environment variables file
.env

# cache dir
cache/

6 changes: 5 additions & 1 deletion app/api/coreApi.js
Expand Up @@ -1183,7 +1183,7 @@ function getCachedMempoolTxSummaries() {
});
}

const mempoolTxSummaryFile = "./mempool-tx-summaries.json";
const mempoolTxSummaryFile = `${config.filesystemCacheDir}/mempool-tx-summaries.json`;

function getMempoolTxSummaries(allTxids, statusId, statusFunc) {
return new Promise(async (resolve, reject) => {
Expand Down Expand Up @@ -1279,6 +1279,10 @@ function getMempoolTxSummaries(allTxids, statusId, statusFunc) {
mempoolTxSummaryCache.lastUpdated = new Date();

try {
if (!fs.existsSync(config.filesystemCacheDir)){
fs.mkdirSync(config.filesystemCacheDir);
}

fs.writeFileSync(mempoolTxSummaryFile, JSON.stringify(mempoolTxSummaryCache));

} catch (e) {
Expand Down
3 changes: 3 additions & 0 deletions app/config.js
Expand Up @@ -6,6 +6,7 @@ const debugLog = debug("btcexp:config");
const fs = require('fs');
const crypto = require('crypto');
const url = require('url');
const path = require('path');

let baseUrl = (process.env.BTCEXP_BASEURL || "/").trim();
if (!baseUrl.startsWith("/")) {
Expand Down Expand Up @@ -98,6 +99,8 @@ module.exports = {

rpcConcurrency: (process.env.BTCEXP_RPC_CONCURRENCY || (slowDeviceMode ? 3 : 10)),

filesystemCacheDir: (process.env.BTCEXP_FILESYSTEM_CACHE_DIR || path.join(process.cwd(),"./cache")),

noTxIndexSearchDepth: (+process.env.BTCEXP_NOTXINDEX_SEARCH_DEPTH || 3),

rpcBlacklist:
Expand Down

0 comments on commit faef9fb

Please sign in to comment.