BiodbPersistentCache: The abstract class for handling file caching.

BiodbPersistentCacheR Documentation

The abstract class for handling file caching.

Description

The abstract class for handling file caching.

The abstract class for handling file caching.

Details

This abstract class is the mother class of concrete classes that manage cache systems 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.

Methods

Public methods


Method new()

New instance initializer. Persistent cache objects must not be created directly. Instead, access the cache instance through the BiodbMain instance using the getPersistentCache() method.

Usage
BiodbPersistentCache$new(cfg, bdb = NULL)
Arguments
cfg

An instance of the BiodbConfig class.

bdb

An instance of the BiodbMain class.

Returns

Nothing.


Method isReadable()

Checks if the cache system is readable.

Usage
BiodbPersistentCache$isReadable(conn = NULL)
Arguments
conn

If not \codeNULL, checks if the cache system is readable for this particular connector.

Returns

\codeTRUE if the cache system is readable, \codeFALSE otherwise.


Method isWritable()

Checks if the cache system is writable.

Usage
BiodbPersistentCache$isWritable(conn = NULL)
Arguments
conn

If not \codeNULL, checks if the cache system is writable for this particular connector.

Returns

\codeTRUE if the cache system is writable, \codeFALSE otherwise.


Method getDir()

Gets the path to the persistent cache folder.

Usage
BiodbPersistentCache$getDir()
Returns

The path to the cache folder as a character value.


Method getFolderPath()

Gets path to the cache system sub-folder dedicated to this cache ID.

Usage
BiodbPersistentCache$getFolderPath(cache.id, create = TRUE, fail = FALSE)
Arguments
cache.id

The cache ID to use.

create

If set to TRUE and the folder does not exist, creates it.

fail

If set to TRUE, throws a warning if the folder does not exist.

Returns

A string containing the path to the folder.


Method folderExists()

Tests if a cache folder exists for this cache ID.

Usage
BiodbPersistentCache$folderExists(cache.id)
Arguments
cache.id

The cache ID to use.

Returns

TRUE if a cache folder exists.


Method getFilePath()

Gets path of file in cache system.

Usage
BiodbPersistentCache$getFilePath(cache.id, name, ext)
Arguments
cache.id

The cache ID to use.

name

A character vector containing file names.

ext

The extension of the files.

Returns

A character vector, the same size as \codenames, containing the paths to the files.


Method filesExist()

Tests if at least one cache file exist for the specified cache ID.

Usage
BiodbPersistentCache$filesExist(cache.id)
Arguments
cache.id

The cache ID to use.

Returns

A single boolean value.


Method fileExist()

DEPRECATED. Use fileExists().

Usage
BiodbPersistentCache$fileExist(cache.id, name, ext)
Arguments
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).

Returns

A logical vector, the same size as \codename, with \codeTRUE value if the file exists in the cache, or \codeFALSE otherwise.


Method fileExists()

Tests if a particular file exist in the cache.

Usage
BiodbPersistentCache$fileExists(cache.id, name, ext)
Arguments
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).

Returns

A logical vector, the same size as \codename, with \codeTRUE value if the file exists in the cache, or \codeFALSE otherwise.


Method markerExist()

DEPRECATED. Use markerExists().

Usage
BiodbPersistentCache$markerExist(cache.id, name)
Arguments
cache.id

The cache ID to use.

name

A character vector containing marker names.

Returns

A logical vector, the same size as \codename, with \codeTRUE value if the marker file exists in the cache, or \codeFALSE otherwise.


Method markerExists()

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.

Usage
BiodbPersistentCache$markerExists(cache.id, name)
Arguments
cache.id

The cache ID to use.

name

A character vector containing marker names.

Returns

A logical vector, the same size as \codename, with \codeTRUE value if the marker file exists in the cache, or \codeFALSE otherwise.


Method setMarker()

Sets a marker.

Usage
BiodbPersistentCache$setMarker(cache.id, name)
Arguments
cache.id

The cache ID to use.

name

A character vector containing marker names.

Returns

Nothing.


Method getTmpFolderPath()

Gets path to the cache system temporary folder.

Usage
BiodbPersistentCache$getTmpFolderPath()
Returns

A string containing the path to the folder.


Method getUsedCacheIds()

Returns a list of cache IDs actually used to store cache files.

Usage
BiodbPersistentCache$getUsedCacheIds()
Returns

A character vector containing all the cache IDs actually used inside the cache system.


Method loadFileContent()

Loads content of files from the cache.

Usage
BiodbPersistentCache$loadFileContent(
  cache.id,
  name,
  ext,
  output.vector = FALSE
)
Arguments
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 \codeTRUE, force output to be a \codevector instead of a \codelist. Where the list contains a \codeNULL, the \codevector will contain an \codeNA value.

Returns

A list (or a vector if \codeoutput.vector is set to \codeTRUE), the same size as \codename, containing the contents of the files. If some file does not exist, a \codeNULL value is inserted inside the list.


Method saveContentToFile()

Saves content to files into the cache.

Usage
BiodbPersistentCache$saveContentToFile(content, cache.id, name, ext)
Arguments
content

A list or a character vector containing the contents of the files. It must have the same length as \codename.

cache.id

The cache ID to use.

name

A character vector containing file names.

ext

The extension of the files.

Returns

Nothing.


Method addFilesToCache()

Adds exisiting files into the cache.

Usage
BiodbPersistentCache$addFilesToCache(
  src.file.paths,
  cache.id,
  name,
  ext,
  action = c("copy", "move")
)
Arguments
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.

action

Specifies if files have to be moved or copied into the cache.

Returns

Nothing.


Method copyFilesIntoCache()

Copies exisiting files into the cache.

Usage
BiodbPersistentCache$copyFilesIntoCache(src.file.paths, cache.id, name, ext)
Arguments
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.

Returns

Nothing.


Method moveFilesIntoCache()

Moves exisiting files into the cache.

Usage
BiodbPersistentCache$moveFilesIntoCache(src.file.paths, cache.id, name, ext)
Arguments
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.

Returns

Nothing.


Method erase()

Erases the whole cache.

Usage
BiodbPersistentCache$erase()
Returns

Nothing.


Method deleteFile()

Deletes a list of files inside the cache system.

Usage
BiodbPersistentCache$deleteFile(cache.id, name, ext)
Arguments
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).

Returns

Nothing.


Method deleteAllFiles()

Deletes, in the cache system, all files associated with this cache ID.

Usage
BiodbPersistentCache$deleteAllFiles(cache.id, fail = FALSE, prefix = FALSE)
Arguments
cache.id

The cache ID to use.

fail

If set to TRUE, a warning will be emitted if no cache files exist for this cache ID.

prefix

DEPRECATED If set to TRUE, use cache.id as a prefix, deleting all files whose cache.id starts with this prefix.

Returns

Nothing.


Method deleteFiles()

Deletes all files with the specific extension of the cache ID in the cache system.

Usage
BiodbPersistentCache$deleteFiles(cache.id, ext)
Arguments
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.

Returns

Nothing.


Method listFiles()

Lists files present in the cache system.

Usage
BiodbPersistentCache$listFiles(
  cache.id,
  ext = NULL,
  extract.name = FALSE,
  full.path = FALSE
)
Arguments
cache.id

The cache ID to use.

ext

The extension of the files, without the dot (\"html\", \"xml\", etc).

extract.name

If set to \codeTRUE, 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 \codeTRUE, returns full path for files.

Returns

The files of found files, or the names of the files if \codeextract.name is set to \codeTRUE.


Method print()

Displays information about this object.

Usage
BiodbPersistentCache$print()

Method enabled()

DEPRECATED method. Use now \codeBiodbConfig :isEnabled('cache.system').

Usage
BiodbPersistentCache$enabled()

Method enable()

DEPRECATED method. Use now \codeBiodbConfig :enable('cache.system').

Usage
BiodbPersistentCache$enable()

Method disable()

DEPRECATED method. Use now \codeBiodbConfig :disable('cache.system').

Usage
BiodbPersistentCache$disable()

Method clone()

The objects of this class are cloneable with this method.

Usage
BiodbPersistentCache$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

BiodbMain, BiodbBiocPersistentCache, BiodbBiocPersistentCache.

Examples

# 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()


pkrog/biodb documentation built on Nov. 29, 2022, 4:24 a.m.