Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use os.UserCacheDir as first fallback if cacheDir is not set #11292

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

bep
Copy link
Member

@bep bep commented Jul 27, 2023

We will now try

  1. cacheDir (or, commonly set in environment as HUGO_CACHEDIR)
  2. if on Netlify we use /opt/build/cache/hugo_cache/
  3. os.UserCacheDir
  4. A temp dir

Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS,
which this commit tries to fix.

This should also make it easier to locate the Hugo cache:

UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own
application-specific subdirectory within this one and use that.

On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it
returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.

If the location cannot be determined (for example, $HOME is not defined), then it will return an error.

Fixes #11286
Fixes #11291

@bep bep force-pushed the feat/cachedir-11286 branch 2 times, most recently from 2b5e752 to 0b239e2 Compare July 27, 2023 14:15
We will now try

1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`)
2. if on Netlify we use `/opt/build/cache/hugo_cache/`
3. os.UserCacheDir
4. A temp dir

Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS,
which this commit tries to fix.

This should also make it easier to locate the Hugo cache:

>UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own
application-specific subdirectory within this one and use that.
>
>On Unix systems, it returns $XDG_CACHE_HOME as specified by
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it
returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache.
>
>If the location cannot be determined (for example, $HOME is not defined), then it will return an error.

Fixes gohugoio#11286
Fixes gohugoio#11291
@bep bep changed the base branch from master to feat/sponsors-in-readme July 27, 2023 16:53
@bep bep changed the base branch from feat/sponsors-in-readme to master July 27, 2023 16:53
@bep bep merged commit b3f1055 into gohugoio:master Jul 27, 2023
7 checks passed
@jmooring
Copy link
Member

Please confirm that this is intended:

$ hugo config | grep -i cachedir
cachedir = '/home/jmooring/.cache/hugo_cache'

I just wanted to check because the typical pattern would be /home/jmooring/.cache/name_of_app.

@bep
Copy link
Member Author

bep commented Jul 27, 2023

I just wanted to check because the typical pattern would be /home/jmooring/.cache/name_of_app.

That's not the pattern for cacheDir.

If you look at https://gohugo.io/getting-started/configuration/#configure-file-caches -- there's also a :project "token".

Anyway, the cacheDir logic is the same as before, just the root may be a little different.

@bep
Copy link
Member Author

bep commented Jul 27, 2023

hugo config | grep -i cachedir

Also, all config keys in that list is lower case, so no need to -i.

Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants