Clear the Cache on Windows with Task Scheduler

Create a Batch File to Clear the Cache

  1. Open Notepad:
    Press Win + R, type notepad, and hit Enter.

  2. Enter the Script:
    Copy and paste the following commands into Notepad. This script will delete all files and folders in your temporary folder:

    @echo off
    echo Clearing cache...
    REM Delete files in the temp folder
    del /q /f "%temp%\*"
    REM Delete folders in the temp folder
    for /d %%p in ("%temp%\*") do rmdir "%%p" /s /q
    echo Cache cleared.
    

    A little note: This script targets the Windows temporary folder (which is generally safe). Always double-check to make sure this is what you want to clear.

  3. Save the File:
    Click File > Save As and set the following:

    • File name: clear_cache.bat
    • Save as type: All Files (.)
    • Location: For example, you can create a folder like C:\Scripts and save it there.

    Then click Save.


Create a Scheduled Task

  1. Open Task Scheduler:
    Press Win + S, type Task Scheduler, and press Enter.

  2. Create a Basic Task:

    • In the Task Scheduler window, click on Create Basic Task... in the right-hand pane.
    • Name and Description:
      • Name: Clear Cache Daily
      • Description: (Optional) Something like “Clears the temporary cache every day.”
    • Click Next.
  3. Set the Trigger:

    • Trigger: Select Daily.
    • Start Date and Time: Choose the day and time you’d like the task to run (for instance, when you’re unlikely to be actively using the PC).
    • Click Next.
  4. Set the Action:

    • Action: Choose Start a program.
    • Program/script:
      • Click Browse... and navigate to where you saved your clear_cache.bat file (e.g., C:\Scripts\clear_cache.bat).
    • Click Next.
  5. Finish the Wizard:
    Review your settings and click Finish.


(Optional) Run with Elevated Privileges

Sometimes deleting files in system directories requires administrative privileges. To ensure the task runs smoothly:

  1. In Task Scheduler, locate your newly created task in the Task Scheduler Library.
  2. Right-click on the task and choose Properties.
  3. Under the General tab, check the box that says Run with highest privileges.
  4. Click OK.

Test the Task

  1. In Task Scheduler, right-click your task and select Run.
  2. Observe if a command prompt window appears and the script executes. You should see the messages “Clearing cache…” and “Cache cleared.”

Comments