Removes cached XML files from the cache directory. Can selectively clear files for a specific department, academic year, or combination of both. If no filters are specified, clears all cached XML files.
Arguments
- name
Character string. Optional department code (e.g., "CS") to clear specific department cache files.
- year
Character string. Optional academic year in YYYYYYYY format (e.g., "20232024") to clear cache files for a specific year.
- cache_dir
Character string. Optional path to the cache directory. If
NULL
, uses the default cache location.
Value
Invisibly returns TRUE
if the operation was successful. Throws an
error if the operation fails.
Details
The function supports three clearing modes based on parameter combinations:
Department-specific: When
name
is providedClears:
"{name}.xml"
or"{name}_{year}.xml"
if year provided
Year-specific: When only
year
is providedClears: All files matching
"*_{year}.xml"
Complete clear: When neither
name
noryear
providedClears: All
"*.xml"
files in cache directory
The function will:
Initialize/verify the cache directory
Determine which files to remove based on parameters
Remove matching files
Display success message with number of files removed
Error Handling
If files cannot be deleted or the cache directory cannot be accessed. The error will include the specific error message and cache directory path.
See also
write_xml_cache()
for writing data to cacheread_xml_cache()
for reading cached datacache_exists()
for checking cache status
Examples
if (FALSE) { # \dontrun{
# Clear all cache files
clear_cache()
# Clear specific department's cache
clear_cache(name = "CS")
# Clear all departments for specific year
clear_cache(year = "20232024")
# Clear specific department and year
clear_cache(name = "CS", year = "20232024")
# Clear cache from custom location
clear_cache(cache_dir = "~/my_course_cache")
} # }