manageCache: Manage the Size of a Cache

Description Usage Arguments Value Examples

View source: R/cacheManagement.R

Description

If cacheDir takes up more than maxCacheSize megabytes on disk, files wll be removed in order of oldest access time. Only files matching extensions are eligible for removal.

Usage

1
2
manageCache(cacheDir, extensions = c("html", "json", "pdf", "png"),
  maxCacheSize = 100)

Arguments

cacheDir

location of cache directory

extensions

vector of file extensions eligible for removal

maxCacheSize

maximum cache size in megabytes

Value

Invisibly returns the number of files removed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Create a cache directory and fill it with 1.6 MB of data
CACHE_DIR <- tempdir()
write.csv(matrix(1,400,500), file=file.path(CACHE_DIR,'m1.csv'))
write.csv(matrix(2,400,500), file=file.path(CACHE_DIR,'m2.csv'))
write.csv(matrix(3,400,500), file=file.path(CACHE_DIR,'m3.csv'))
write.csv(matrix(4,400,500), file=file.path(CACHE_DIR,'m4.csv'))
for (file in list.files(CACHE_DIR, full.names=TRUE)) {
  print(file.info(file)[,c(1,6)])
}
# Remove files based on last access time until we get under 1 MB
manageCache(CACHE_DIR, extensions='csv', maxCacheSize=1)
for (file in list.files(CACHE_DIR, full.names=TRUE)) {
  print(file.info(file)[,c(1,6)])
}

MazamaScience/MazamaWebUtils documentation built on May 29, 2019, 2:09 p.m.