Skip to contents

A class to handle caching of objects, files, or directories. It generates a signature from the provided object and creates cached versions based on that signature.

Public fields

cache_dir

Directory where cached files are stored

Methods


Method new()

Initialize a new Cache object

Usage

Cache$new(
  sig_object,
  prefix,
  cache_dir,
  save_sig = FALSE,
  kind = c("object", "file", "dir")
)

Arguments

sig_object

Object used to generate the cache signature

prefix

Prefix for the cache filename

cache_dir

Directory where cached files are stored

save_sig

Whether to save the signature to a file

kind

Type of cache: "object", "file", or "dir"

Returns

A new Cache object


Method clear()

Clear the current cached object/file/directory

Usage

Cache$clear()


Method clear_all()

Clear all cached objects in the cache directory Be careful with this operation as it will remove all cached files in the cache directory

Usage

Cache$clear_all()


Method get()

Retrieve the cached object/file/directory When NULL is returned, it means the cache does not exist

Usage

Cache$get(target = NULL)

Arguments

target

Target path for file/directory cache (required for file/dir kind)

Returns

For objects: the cached object or NULL if not found For files/dirs: the target path or NULL if not found


Method is_cached()

Check if we have a cached object/file/directory

Usage

Cache$is_cached()

Returns

TRUE if the cached object/file/directory exists, FALSE otherwise


Method get_path()

Get the path to the cached object/file/directory

Usage

Cache$get_path()

Returns

The path to the cached object/file/directory


Method save()

Save an object/file/directory to cache

Usage

Cache$save(data)

Arguments

data

The object to cache, or path to file/directory to cache


Method clone()

The objects of this class are cloneable with this method.

Usage

Cache$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.