clear_cache Subroutine

public subroutine clear_cache(custom_cache_dir, success)

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: custom_cache_dir
logical, intent(out) :: success

Source Code

    subroutine clear_cache(custom_cache_dir, success)
        character(len=*), intent(in) :: custom_cache_dir
        logical, intent(out) :: success
        character(len=256) :: cache_dir
        character(len=:), allocatable :: command
        integer :: exitstat, cmdstat

        success = .false.

        ! Get cache directory
        if (len_trim(custom_cache_dir) > 0) then
            cache_dir = trim(custom_cache_dir)
        else
            cache_dir = get_cache_dir()
        end if

        ! Check if cache directory exists
        inquire (file=trim(cache_dir), exist=success)
        if (.not. success) then
            ! No cache directory, nothing to clear
            success = .true.
            return
        end if

        ! Clear cache directory contents
        ! Use platform-specific commands
        if (get_os_type() == OS_WINDOWS) then
            command = 'rmdir /S /Q "'//trim(escape_shell_arg(cache_dir))//'"'
        else
            command = 'rm -rf "'//trim(escape_shell_arg(cache_dir))//'"'
        end if

        call execute_command_line(command, exitstat=exitstat, cmdstat=cmdstat)

        if (cmdstat == 0 .and. exitstat == 0) then
            success = .true.
        end if

    end subroutine clear_cache