ffscrapr: Managing Cache

Tan Ho

2023-02-11

Caching: It’s Responsible Web Etiquette!

One of the many packages that inspired ffscrapr is Dmytro Perepolkin’s polite package, which sets out some pillars of responsible web etiquette, including introducing yourself, taking slowly, and never asking twice for the same thing.

ffscrapr gives you convenient routes to support these:

This vignette explains and helps you manage this caching.

What is being cached? How long is it being cached for?

ffscrapr’s core functions often loop over the same, stable endpoints to help return the data for each function - things like “player names/positions/teams”, “franchise IDs/names”, and “league scoring rules” are all used frequently. ffscrapr incorporates memoise package to help with this functionality, and (as of this writing) saves the results of these functions:

You can find an updated list of cached functions in the zzz.R source code page.

Where is it being cached?

By default, ffscrapr will save the results of each function call (i.e. function + arguments) into memory.

If you would like to have your cache stored on your local filesystem, you can adjust this behaviour by adding the following line to your (or your project) .Rprofile, or by adding it BEFORE you library/load the package.

options(ffscrapr.cache = "filesystem")

This will instruct ffscrapr to store the cache on your machine, as dictated by the typical cache location for your operating system. You can see where this is by running the following line of code:

rappdirs::user_cache_dir("ffscrapr")

How can I clear the cache?

You can use the following function to clear the cache (whether it is in memory or on your filesystem):

.ffscrapr_clear_cache()