BiodbPersistentCache-class {biodb} | R Documentation |
This class manages a cache system for saving downloaded files and request results.
It is designed for internal use, but you can still access some of the read-only methods if you wish.
Inside the cache folder, one folder is created for each cache ID (each remote database has one single cache ID, always the same ,except if you change its URL). In each of theses folders are stored the cache files for this database.
deleteAllFiles(cache.id, fail = FALSE, prefix = FALSE)
:
Deletes, in the cache system, all files associated with this cache ID.
cache.id: The cache ID to use.
prefix: If set to TRUE, use cache.id as a prefix, deleting all files whose cache.id starts with this prefix.
fail: If set to TRUE, a warning will be emitted if no cache files exist for this cache ID.
Returned value: None.
deleteFile(cache.id, name, ext)
:
Deletes a list of files inside the cache system.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files, without the dot ("html", "xml", etc).
Returned value: None.
deleteFiles(cache.id, ext)
:
Deletes all files with the specific extension of the cache ID in the cache system.
cache.id: The cache ID to use.
ext: The extension of the files, without the dot ("html", "xml", etc). Only files having this extension will be deleted.
Returned value: None.
disable()
:
DEPRECATED method. Use now
BiodbConfig::disable('cache.system')
.
enable()
:
DEPRECATED method. Use now
BiodbConfig::enable('cache.system')
.
enabled()
:
DEPRECATED method. Use now
BiodbConfig::isEnabled('cache.system')
.
erase()
:
Erases the whole cache.
Returned value: None.
fileExist(cache.id, name, ext)
:
Tests if a particular file exist in the cache.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files, without the dot ("html", "xml", etc).
Returned value: A logical vector, the same size as name
, with
TRUE
value if the file exists in the cache, or FALSE
otherwise.
filesExist(cache.id)
:
Tests if at least one cache file exist for the specified cache ID.
cache.id: The cache ID to use.
Returned value: A single boolean value.
getDir()
:
Gets the absolute path to the cache directory.
Returned value: The absolute path of the cache directory.
getFilePath(cache.id, name, ext)
:
Gets path of file in cache system.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files.
Returned value: A character vector, the same size as names
,
containing the paths to the files.
getFolderPath(cache.id)
:
Gets path to the cache system sub-folder dedicated to this cache ID.
cache.id: The cache ID to use.
Returned value: A string containing the path to the folder.
getTmpFolderPath()
:
Gets path to the cache system temporary folder.
Returned value: A string containing the path to the folder.
getUsedCacheIds()
:
Returns a list of cache IDs actually used to store cache files.
Returned value: A character vector containing all the cache IDs actually used inside the cache system.
getVersion()
:
Returns the cache version.
Returned value: The current cache version.
isReadable(conn = NULL)
:
Checks if the cache system is readable.
conn: If not NULL
, checks if the cache system is readable for
this particular connector.
Returned value: TRUE
if the cache system is readable,
FALSE
otherwise.
isWritable(conn = NULL)
:
Checks if the cache system is writable.
conn: If not NULL
, checks if the cache system is writable for
this particular connector.
Returned value: TRUE
if the cache system is writable,
FALSE
otherwise.
listFiles(
cache.id,
ext = NA_character_,
extract.name = FALSE,
full.path = FALSE
)
:
Lists files present in the cache system.
cache.id: The cache ID to use.
ext: The extension of the files, without the dot ("html", "xml", etc).
extract.name: If set to TRUE
, instead of returning the file paths,
returns the list of names used to construct the file name:
[cache_folder]/[cache.id]/[name].[ext].
full.path: If set to TRUE
, returns full path for files.
Returned value: The files of found files, or the names of the files if
extract.name
is set to TRUE
.
loadFileContent(cache.id, name, ext, output.vector = FALSE)
:
Loads content of files from the cache.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files.
output.vector: If set to TRUE
, force output to be a vector
instead of a list
. Where the list contains a NULL
, the
vector
will contain an NA
value.
Returned value: A list (or a vector if output.vector
is set to
TRUE
), the same size as name
, containing the contents of the
files. If some file does not exist, a NULL
value is inserted inside
the list.
markerExist(cache.id, name)
:
Tests if markers exist in the cache. Markers are used, for instance, by biodb to remember that a downloaded zip file from a database has been extracted correctly.
cache.id: The cache ID to use.
name: A character vector containing marker names.
Returned value: A logical vector, the same size as name
, with
TRUE
value if the marker file exists in the cache, or FALSE
otherwise.
moveFilesIntoCache(src.file.paths, cache.id, name, ext)
:
Moves exisiting files into the cache.
src.file.paths: The current paths of the source files, as a character vector.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files.
Returned value: None.
saveContentToFile(content, cache.id, name, ext)
:
Saves content to files into the cache.
content: A list or a character vector containing the contents of the
files. It must have the same length as name
.
cache.id: The cache ID to use.
name: A character vector containing file names.
ext: The extension of the files.
Returned value: None.
setMarker(cache.id, name)
:
Sets a marker.
cache.id: The cache ID to use.
name: A character vector containing marker names.
Returned value: None.
# Create an instance with default settings: mybiodb <- biodb::newInst() # Get a compound CSV file database chebi.tsv <- system.file("extdata", "chebi_extract.tsv", package='biodb') # Get a connector instance: conn <- mybiodb$getFactory()$createConn('comp.csv.file', url=chebi.tsv) # Get all entries entries <- conn$getEntry(conn$getEntryIds()) # Get the cache instance: cache <- mybiodb$getPersistentCache() # Get list of files inside the cache: files <- cache$listFiles(conn$getCacheId()) # Delete files inside the cache: cache$deleteAllFiles(conn$getCacheId()) # Terminate instance. mybiodb$terminate()