From 2187cf737c6efc95c9b7c361b7a9fc6e81e332c3 Mon Sep 17 00:00:00 2001 From: Dick Wolff Date: Sat, 10 Feb 2024 10:22:53 +0100 Subject: [PATCH] Add cache purging support to Docker container --- README.md | 5 +++++ src/watcher.ts | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index d38d4ab..ff19390 100644 --- a/README.md +++ b/README.md @@ -87,11 +87,16 @@ The following parameters can be given to the Docker run command. | `--env USE_POLLING=true` | Y | When set to true, the container will continously look for new files to process and the container will not stop. | | `--env DEBUG_LOGGING=true` | Y | When set to true, the container will show logs in more detail, useful for error tracing. | | `--env FORCE_DEGIRO_V2=true` | Y | When set to true, the converter will use the DEGIRO V2 converter (currently in beta) when a DEGIRO file was found. | +| `--env PURGE_CACHE=true` | Y | When set to true, the file cache will be purged on start. | 1: You can retrieve your Ghostfolio account ID by going to Accounts > select your account and copying the ID from the URL. ![image](https://user-images.githubusercontent.com/5620002/203353840-f5db7323-fb2f-4f4f-befc-e4e340466a74.png) +### Caching + +The tool uses `cacache` to store data retrieved from Yahoo Finance inside the container. This way the load on Yahoo Finance is reduced and the tool should run faster. The cached data is stored inside the container in `tmp/e2g-cache`. If you feel you need to invalidate your cache, you can do so by adding `--env PURGE_CACHE=true` to your run command. This will clear the cache on container start, and the tool will recreate the cache the next time it has to retrieve data from Yahoo Finance. + ## Run locally diff --git a/src/watcher.ts b/src/watcher.ts index a678602..baef91d 100644 --- a/src/watcher.ts +++ b/src/watcher.ts @@ -1,9 +1,20 @@ import path from "path"; import * as fs from "fs"; import chokidar from "chokidar"; +import * as cacache from "cacache"; import * as matcher from "closest-match"; import { createAndRunConverter } from "./converter"; +// Check if the cache should be purged. +if (Boolean(process.env.PURGE_CACHE)) { + + console.log("[i] Purging cache (PURGE_CACHE set to true).."); + Promise.all([ + cacache.rm("tmp/e2g-cache", "isinSymbolCache"), + cacache.rm("tmp/e2g-cache", "symbolCache") + ]).then(() => console.log("[i] Cache purged!")); +} + // Define input and output. const inputFolder = process.env.E2G_INPUT_FOLDER || "/var/e2g-input"; const outputFolder = process.env.E2G_OUTPUT_FOLDER || "/var/e2g-output";