Prevent Netlify from trying to make caches directory

I have something like this in my config.toml

[caches]
[caches.getjson]
  dir = "/Users/me/my/path/cache"

If I try to deploy via Netlify I get Error: failed to create file caches from configuration: mkdir /Users: permission denied.

I only need the caching when using the dev server. How do I configure that?

I tried changing the config to the below, but it didn’t seem to make any difference.

[server]
  [caches]
  [caches.getjson]
    dir = "/Users/me/my/path/cache"

By using the --cacheDir CLI flag.

ref: https://gohugo.io/commands/hugo/#options

I’m not too sure about that, but I guess that depends (if you’re processing images, it is a big win to cache also on Netlify). Hugo detects if you’re running on Netlify and sets the cache dir (if not set by you) to a Netlify path that survives builds.

There are several options:

  • set cacheDir to something else (either as a flag or via a separate dev/prod config, see the section about config dirs in the docs )
  • turn off caching

OK, so I should set the directory to the default during build. Which would be this $TMPDIR/hugo_cache ?
Via a flag seems straight forward (hugo --cacheDir $TMPDIR/hugo_cache/), but the docs suggested to me the config option would be that in my original post. Would it be this instead then?

[caches]
[caches.getjson]
  dir = "/Users/me/my/path/cache"

[build]
  [caches]
  [caches.getjson]
    dir = "$TMPDIR/hugo_cache/"

(I’m caching content from an API)

Configuration directories.

Thanks maiki. I understand the approach now, still not quite got it working though.

I have made a file named caches.toml in /config/development/. In that file I have put my

[caches.getjson]
  dir = "/Users/me/my/path/cache"

When running hugo server I get Error: failed to create file caches from configuration: "caches" is not a valid cache name. What have I missed?

Pretty sure you want those in a config.toml file, rather than a cache.toml.

You’re right, that’s working now. Thanks.

Any way to tell Hugo not to try to use .DS_Store as a config file?

I don’t use an OS that creates those files… so I guess my recommendation is the same. :slight_smile:

add this files in .gitignore, so it will not be in your git depot.

They are globally ignored, the DS_Store issue is a local one.

Try entering ignoreFiles in your config or recursively remove all instances of DS_Store with a script from your project.

This topic was automatically closed after 6 days. New replies are no longer allowed.