Skip to content

Commit

Permalink
Allow to override the cache dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Nov 16, 2023
1 parent 71ecfcb commit 2510b8b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/cache.toit
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,20 @@ class Cache:
/**
Creates a new cache.
If the \$XDG_CACHE_HOME environment variable is set, the cache is located
at \$XDG_CACHE_HOME/$app-name. Otherwise, the cache will is stored
in \$(HOME)/.cache/$app-name.
Determines the cache directory in the following order:
- If APP_CACHE_DIR (where "APP" is the uppercased version of $app-name) is set,
uses it as the path to the cache.
- If the \$XDG_CACHE_HOME environment variable is set, the cache is located
at \$XDG_CACHE_HOME/$app-name.
- Otherwise, the cache directory is set to \$(HOME)/.cache/$app-name.
*/
constructor --app-name/string:
app-name-upper := app-name.to-ascii-upper
env := os.env
if env.contains "$(app-name-upper)_CACHE_DIR":
path := env["$(app-name-upper)_CACHE_DIR"]
return Cache --app-name=app-name --path=path

cache-home := xdg.cache-home
return Cache --app-name=app-name --path="$cache-home/$(app-name)"

Expand Down

0 comments on commit 2510b8b

Please sign in to comment.