Remember the past to be quicker in the future
Caching makes styler faster on repeated styling and is shared across all APIs
(e.g. style_text()
and Addin).
That means if you style code that already complies to a
style guide and you have previously styled that code, it will be quicker.
See cache_info()
,cache_activate()
or cache_clear()
for utilities to
manage the cache. You can deactivate it altogether with cache_deactivate()
.
Since we leverage {R.cache}
to manage the cache, you can also use any
{R.cache}
functionality to manipulate it.
{styler}
by default uses caching via the {R.cache}
package. When interacting
with {styler}
, you will be asked to let it create a permanent cache on your
file system that styler will use in case it is not set already up for another
tool that uses {R.cache}
. We encourage users to let {R.cache}
create a
permanent directory for caching because, otherwise, the cache is lost at
restart of R.
In some cases, you want to avoid the interactive prompt described above. In
that situation, you can set the path to the cache with the R option
R.cache.rootPath
or the environment variable R_CACHE_ROOTPATH
to an
existent path before you call the styler API. This should avoid the prompt.
R.cache::setCacheRootPath("/path/to/cache")
is also programmatic but will
probably give the prompt anyways if called interactively.
Note that if you have never authorized {R.cache}
to create the cache in a
permanent directory and you use {styler}
non-interactively, it will build the
cache in a temporary directory. To create a permanent cache, follow the
section 'Non-interactive setup' or 'Interactive setup' above.
The cache is specific to a version of styler by default, because different versions potentially format code differently. This means after upgrading styler or a style guide you use, the cache will be re-built.
The cache works by storing hashed output code as a whole and by expression, which is why it takes zero space on disk (the cache is a directory with empty files which have the hash of output code as name).
If you want to set up caching in a CI/CD pipeline, we suggest to set the
{R.cache}
root path to a directory for which you have the cache enabled as
described above in the section 'Non-interactive setup'. This can often be set
in config files of CI/CD tools, e.g. see the
Travis documentation on caching.
Other cache managers:
cache_activate()
,
cache_clear()
,
cache_info()
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.