Skip to contents

Retrieves cached XML course data for a specific department and optional academic year. Returns NULL if the requested cache file does not exist, allowing for graceful fallback to fresh API requests.

Usage

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

Arguments

name

Character string. Department code to read from cache (e.g., "CS" for Computer Science).

year

Character string. Optional academic year in YYYYYYYY format (e.g., "20232024"). When provided, looks for a file with "_YYYYYYYY" suffix.

cache_dir

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

Value

Returns one of:

  • An xml2 document object containing the cached data if found

  • NULL if the cache file does not exist

Details

The function looks for cache files using the following pattern: {name}{_year}.xml. For example:

  • Without year: "CS.xml"

  • With year: "CS_20232024.xml"

The function will:

  • Initialize/verify the cache directory

  • Construct the appropriate filename with optional year suffix

  • Check if the cache file exists

  • Read and parse the XML file if found

  • Return NULL if file not found

Error handling

If the XML file exists but cannot be read or parsed. The error will include the department name, file path, and specific error message.

See also

Examples

if (FALSE) { # \dontrun{
# Read current year's CS department data
xml_doc <- read_xml_cache("CS")

# Read specific academic year
xml_doc <- read_xml_cache("CS", "20232024")

# Handle missing cache gracefully
xml_doc <- read_xml_cache("CS")
if (is.null(xml_doc)) {
  # Cache miss - fetch from API instead
  xml_doc <- fetch_department_courses_raw("CS")
}
} # }