cache_directory()
returns the on-disk location of
the cache used by OLSr.
cache_summary()
reports the number and size of files
in the cache, the oldest file, etc.
cache_info()
reports information about each file in
the cache.
cache()
returns an object that can be used in cache
management.
Usage
cache_directory()
cache_summary()
cache_info()
cache()
# S3 method for cache_summary
print(x, ...)
Arguments
- x
for
print.cache_summary()
, an object returned by `cache_summary().- ...
ignored by
print.cache_summary()
.
Value
cache_directory() returns the character(1) path to the location of the cache on disk.
cache_summary()
returns a list with the following elements:
directory
: the location of the cache, i.e.,cache_directory()
.n_files
: the number of files in the cache.cache_size
: the sum of file sizes in the cache.largest_file
,largest_size
: the largest file and its size in the cache.oldest_file
,oldest_age
: the name and age (as adifftime
object) of the oldest (based onctime
) file in the path.least_used_file
,least_used_age
: the name and age of the file that was modified least recently, based onmtime
.
print.cache_summary()
displays this information in a readable
way.
cache_info()
returns a tibble with columns summarizing
file
: the file name of the cache entry. This is a hash, based on the function and signature, of the cached object. It is not easily possible to associate individual calls in R to file names.size
the size in bytes of the cached object.mtime
,ctime
,atime
: the modification, creation and last-access time of the file.
cache()
returns an object defined in the cachem package.
Details
OLSr uses an on-disk cache to improve performance and reliability. Each query to the OLS server is cached on first use, so that subsequent responses can be read from the local disk. This greatly increases performance, and allows use of previously retrieved resources when off-line.
A risk of using a cache is that the cache contains an 'old' version of the response. Circumvent this risk by manually manipulating the cache, e.g., removing objects that a known to be too old.
OLSr uses the memoise https://CRAN.R-project.org/package=memoise
and cachem https://CRAN.R-project.org/package=cachem packages to
implement the cache. The disk cache is implemented using cachem's
cache_disk()
function using the default cache size (1 Gb) and
"lsu"
('least recently used') eviction policy. Objects remain in
the cache for 30 days.
The cache is created in a package-specific directory, located at
cache_directory()
.
See the help page ?cache_disk
for information on using the object
returned by cache()
.
Examples
cache_directory()
#> [1] "/home/runner/.cache/R/OLSr"
cache_summary()
#> cache directory: /home/runner/.cache/R/OLSr
#> number of files: 0
#> total cache size: 0 bytes
#> largest file: 0 B
#> oldest file: 0 secs
#> least used file: 0 secs
cache_info()
#> # A tibble: 0 × 11
#> # ℹ 11 variables: file <chr>, size <dbl>, isdir <lgl>, mode <octmode>,
#> # mtime <dttm>, ctime <dttm>, atime <dttm>, uid <int>, gid <int>,
#> # uname <chr>, grname <chr>
## cache objects created in the last 24 hours
cache_info() |>
filter(mtime > Sys.time() - 24 * 60 * 60)
#> # A tibble: 0 × 11
#> # ℹ 11 variables: file <chr>, size <dbl>, isdir <lgl>, mode <octmode>,
#> # mtime <dttm>, ctime <dttm>, atime <dttm>, uid <int>, gid <int>,
#> # uname <chr>, grname <chr>
if (FALSE) {
## remove the most recently modified object, forcing this to be recreated
file_name <-
cache_info() |>
arrange(desc(mtime)) |>
slice(1) |>
pull(file)
unlink(file.path(cache_directory(), file_name))
}
cache()
#> <cache_disk> <cachem>
#> Methods:
#> get(key, missing = missing_)
#> set(key, value)
#> exists(key)
#> keys()
#> remove(key)
#> reset()
#> prune()
#> size()
#> destroy()
#> is_destroyed(throw = FALSE)
#> info()