createCache {reproducible} | R Documentation |
Low-level functions to create and work with a cache
Description
These are intended for advanced use only.
Usage
createCache(
cachePath = getOption("reproducible.cachePath"),
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
force = FALSE,
verbose = getOption("reproducible.verbose")
)
loadFromCache(
cachePath = getOption("reproducible.cachePath"),
cacheId,
preDigest,
fullCacheTableForObj = NULL,
format = getOption("reproducible.cacheSaveFormat", "rds"),
.functionName = NULL,
.dotsFromCache = NULL,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
verbose = getOption("reproducible.verbose")
)
extractFromCache(sc, elem, ifNot = NULL)
rmFromCache(
cachePath = getOption("reproducible.cachePath"),
cacheId,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL),
format = getOption("reproducible.cacheSaveFormat", "rds")
)
CacheDBFile(
cachePath = getOption("reproducible.cachePath"),
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL)
)
CacheStorageDir(cachePath = getOption("reproducible.cachePath"))
CacheStoredFile(
cachePath = getOption("reproducible.cachePath"),
cacheId,
format = NULL,
obj = NULL
)
CacheDBTableName(
cachePath = getOption("reproducible.cachePath"),
drv = getDrv(getOption("reproducible.drv", NULL))
)
CacheIsACache(
cachePath = getOption("reproducible.cachePath"),
create = FALSE,
drv = getDrv(getOption("reproducible.drv", NULL)),
conn = getOption("reproducible.conn", NULL)
)
Arguments
cachePath |
A path describing the directory in which to create the database file(s) |
drv |
A driver, passed to |
conn |
an optional DBIConnection object, as returned by dbConnect(). |
force |
Logical. Should it create a cache in the |
verbose |
Numeric, -1 silent (where possible), 0 being very quiet,
1 showing more messaging, 2 being more messaging, etc.
Default is 1. Above 3 will output much more information about the internals of
Caching, which may help diagnose Caching challenges. Can set globally with an
option, e.g., |
cacheId |
The cacheId or otherwise digested hash value, as character string. |
preDigest |
The list of |
fullCacheTableForObj |
The result of |
format |
The text string representing the file extension used normally by
different save formats; currently only |
.functionName |
Optional. Used for messaging when this function is called from |
.dotsFromCache |
Optional. Used internally. |
sc |
a cache tags |
elem |
character string specifying a |
ifNot |
character (or NULL) specifying the return value to use if |
obj |
The optional object that is of interest; it may have an attribute "saveRawFile" that would be important. |
create |
Logical. Currently only affects non RSQLite default drivers.
If |
Details
-
createCache()
will create a Cache folder structure and necessary files, based on the particulardrv
orconn
provided;
-
loadFromCache()
retrieves a single object from the cache, given itscacheId
;
-
extractFromCache()
retrieves a singletagValue
from the cache based on thetagKey
ofelem
;
-
rmFromCache()
removes one or more items from the cache, and updates the cache database files.
Value
-
createCache()
returnsNULL
(invisibly) and intended to be called for side effects;
-
loadFromCache()
returns the object from the cache that has the particularcacheId
;
-
extractFromCache()
returns thetagValue
from the cache corresponding toelem
if found, otherwise the value ofifNot
;
-
rmFromCache()
returnsNULL
(invisibly) and is intended to be called for side effects;
-
CacheDBFile()
returns the name of the database file for a given Cache, whenuseDBI() == FALSE
, orNULL
ifTRUE
; -
CacheDBFiles()
(i.e,. plural) returns the name of all the database files for a given Cache whenuseDBI() == TRUE
, orNULL
ifFALSE
; -
CacheStoredFile()
returns the file path to the file with the specified hash value, This can be loaded to memory with e.g.,loadFile()
.;
-
CacheStorageDir()
returns the name of the directory where cached objects are stored;
-
CacheStoredFile
returns the file path to the file with the specified hash value;
-
CacheDBTableName()
returns the name of the table inside the SQL database, if that is being used;
-
CacheIsACache()
returns a logical indicating whether thecachePath
is currently areproducible
cache database;
Examples
data.table::setDTthreads(2)
newCache <- tempdir2()
createCache(newCache)
out <- Cache(rnorm(1), cachePath = newCache)
cacheId <- gsub("cacheId:", "", attr(out, "tags"))
loadFromCache(newCache, cacheId = cacheId)
rmFromCache(newCache, cacheId = cacheId)
# clean up
unlink(newCache, recursive = TRUE)
data.table::setDTthreads(2)
newCache <- tempdir2()
# Given the drv and conn, creates the minimum infrastructure for a cache
createCache(newCache)
CacheDBFile(newCache) # identifies the database file
CacheStorageDir(newCache) # identifies the directory where cached objects are stored
out <- Cache(rnorm(1), cachePath = newCache)
cacheId <- gsub("cacheId:", "", attr(out, "tags"))
CacheStoredFile(newCache, cacheId = cacheId)
# The name of the table inside the SQL database
CacheDBTableName(newCache)
CacheIsACache(newCache) # returns TRUE
# clean up
unlink(newCache, recursive = TRUE)