MazamaWebUtils (version 0.1.7)

manageCache: Manage the Size of a Cache

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

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

Run this code
# NOT RUN {
# 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)])
}
# }

Run the code above in your browser using DataLab