Writes XML course data to the cache directory. The function handles the creation
of appropriately named cache files based on department code and optional academic
year. Cache files are stored as XML documents with the extension .xml
.
Arguments
- xml_doc
An
xml2
document object containing course or department data to be cached.- name
Character string. Base filename for the cache file, typically a department code (e.g., "CS" for Computer Science).
- year
Character string. Optional academic year in YYYYYYYY format (e.g., "20232024"). When provided, appends "_YYYYYYYY" to the filename.
- cache_dir
Character string. Optional path to the cache directory. If
NULL
, uses the default cache location.
Details
The function constructs the cache filename using the following pattern:
{name}{_year}.xml
. For example:
Without year: "CS.xml"
With year: "CS_20232024.xml"
The function will:
Initialize/create the cache directory if needed
Construct the appropriate filename with optional year suffix
Write the XML document to the cache location
Handle any errors during the write process
Error Handling
If the XML document cannot be written to the cache location. The error will include the department name, attempted file path, and specific error message.
See also
init_cache_dir()
for cache directory initializationread_xml_cache()
for reading cached XML dataclear_cache()
for removing cached files
Examples
if (FALSE) { # \dontrun{
# Cache current year's CS department data
xml_doc <- fetch_department_courses_raw("CS")
write_xml_cache(xml_doc, "CS")
# Cache specific academic year
xml_doc <- fetch_department_courses_raw("CS", "20232024")
write_xml_cache(xml_doc, "CS", "20232024")
} # }