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 provided cache home to store cached files #182

Open
mojavelinux opened this issue Apr 11, 2018 · 6 comments
Open

Use OS provided cache home to store cached files #182

mojavelinux opened this issue Apr 11, 2018 · 6 comments

Comments

@mojavelinux
Copy link
Member

mojavelinux commented Apr 11, 2018

I recently (re)discovered the XDG basedir standard, which specifies a standard location for storing cache files for an application (particularly on Linux). I think Asciidoctor Diagram should follow this standard where possible.

The logic is pretty simple. The application directory should be created inside the directory specified by XDG_CACHE_HOME, which is typically ~/.cache. In our case, the location would be $XDG_CACHE_HOME/asciidoctor/diagram.

In the event this environment variable is not specified, there are generally accepted fallbacks which can be found in the xdg-basedir npm package. See https://github.com/sindresorhus/xdg-basedir/blob/master/index.js

@mojavelinux
Copy link
Member Author

We might also consider allowing the cache to be specified explicitly using an attribute such as asciidoctor-cachedir. This would override the default location.

@mojavelinux
Copy link
Member Author

The benefit of making this change is that cache directories don't get spread all over the place, which primarily comes into place when using Asciidoctor Diagram in a site generator.

@mojavelinux mojavelinux changed the title Use XDG cache to store cached files Use XDG cache home to store cached files Apr 11, 2018
@pepijnve pepijnve changed the title Use XDG cache home to store cached files Use OS provided cache home to store cached files Apr 11, 2018
@pepijnve
Copy link
Member

I generalised this issue to one where we use the OS provided user cache directory, not just the XDG stuff on Linux.

@mojavelinux
Copy link
Member Author

Exactly!

@pepijnve
Copy link
Member

Couple of implementation details that need to be figured out:

  • Should this only be used if the safe mode allows it? By default we'll be escaping the jail
  • What do we use as cache key? At the moment the cache logic assumes it's per document and uses the image name as key. In the case of a shared cache for multiple documents we need some conflict resolution scheme.

@mojavelinux
Copy link
Member Author

Should this only be used if the safe mode allows it? By default we'll be escaping the jail

Since it's a well-defined location that's generally accepted as read/write, I think it's fine in this case. But if we want to be absolutely strict, then we'd have to require the use of unsafe mode. But seeing that no other program imposes that kind of requirement, I think that would be overkill.

What do we use as cache key? At the moment the cache logic assumes it's per document and uses the image name as key.

I think we can continue doing that. We're really just talking about where the base directory is, so the cache doesn't get scattered across the filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants