Skip to contents

Checks for the existence of cached XML files in the cache directory. Can check for files for a specific department, academic year, or combination of both. If no filters are specified, checks if any cache files exist.

Usage

cache_exists(name = NULL, year = NULL, cache_dir = NULL)

Arguments

name

Character string. Optional department code (e.g., "CS") to check for specific department cache files.

year

Character string. Optional academic year in YYYYYYYY format (e.g., "20232024") to check for cache files from a specific year.

cache_dir

Character string. Optional path to the cache directory. If NULL, uses the default cache location.

Value

A logical value:

  • TRUE if matching cache files exist

  • FALSE if no matching files found or if check fails

Details

The function supports three checking modes based on parameter combinations:

  1. Department-specific: When name is provided

    • Checks for: "{name}.xml" or "{name}_{year}.xml" if year provided

  2. Year-specific: When only year is provided

    • Checks for: Any files matching "*_{year}.xml"

  3. General check: When neither name nor year provided

    • Checks for: Any "*.xml" files in cache directory

On error (e.g., permission issues), the function:

  • Issues a warning with error details

  • Returns FALSE to allow graceful error handling

See also

Examples

if (FALSE) { # \dontrun{
# Check if any cache exists
if (cache_exists()) {
  # Process cached data
}

# Check specific department cache
if (cache_exists(name = "CS")) {
  cached_data <- read_xml_cache("CS")
}

# Check specific year
if (cache_exists(year = "20232024")) {
  # Process cached data for year
}

# Check specific department and year
if (cache_exists(name = "CS", year = "20232024")) {
  cached_data <- read_xml_cache("CS", "20232024")
}
} # }