Clear Cache in Chrome - Powershell or Cmd Prompt

Gurus,
I have a process that runs for a bit and unfortunately I see chrome crashing with “Aw Snap”.

In order to overcome this issue I am trying to clear the cache periodically via a Powershell or cmd line. I don’t want to use the screen so it appears seamless to the end user. I tried to use the link below with little luck Clear Cache in Chrome

Any guidance would be much appreciated.

Thanks,
Kaushik

1 Like

Below PowerShell script should work.
It deletes the contents of the Cache folder in %LocalAppData%\Google\Chrome\User Data\Default\Cache
Please note, this will kill chrome first.

taskkill /F /IM "chrome.exe"
Start-Sleep -Seconds 5
$Items = @('Archived History',
            'Cache\*',
            'Cookies',
            'History',
            'Login Data',
            'Top Sites',
            'Visited Links',
            'Web Data')
$Folder = "$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default"
$Items | % { 
    if (Test-Path "$Folder\$_") {
        Remove-Item "$Folder\$_" 
    }
}
1 Like

@KannanSuresh,
Thank you.

I will try and keep you posted

this one looks fancy and does for more browser in case you ever need…

When I am trying above code I am getting below error . I changed type argument to string then it’s working.


1 Like

Hello everyone,

I will share a solution about automatic cache clearing for you.

First we need to specify a variable. Let’s name this variable “counter”. After adding the variable named “counter” from the “Variables” tab, select the variable type “int32”. Indicates that this variable is a numeric value. Thanks to this, we will perform a simple mathematical operation.

After determining our variable, let’s drag an assing event to the beginning of our project. Let’s write the “counter” variable that we added to our project in the variable section, and write 0 in the value section. In this way, when our project runs, our “counter” variable will take its value.

After doing this, we will determine the condition of our project. First of all, “after how many operations will our browser’s cache be deleted?” The question needs an answer. I’m assuming I want the cache cleared once in 10 operations. For this, for my “counter” variable to increase by one after each operation is completed; Assing opens the event and “counter” in the variable section and “counter +1” in the value section, so that the counter will increase by 1 each time while my process cycle continues. now i will write my cache clear condition which will run if counter exceeds 10 at the beginning of my process.

Cache Clearing

I’m dragging my while loop into my project where my process starts. First, I start my use browser activity and select my browser. Then I drag and drop my Go to url event and write “chrome://settings/clearBrowserData” in the url field. Then I drag the click event to my project and target my delete history button. I’m saving my “counter” variable as the assign event is equal to 0, so I want it to count up to 10 again in the loop. Save your session password, as this process will cause you to log out of the transaction you have made with your session open. You can target the page you will log in to with the go to url activity and enable you to log in again with the click activity.

I hope this is a useful information for you.
If you have any questions, feel free to write.

Thank you Best regards

Use this powershell

ps chrome -ErrorAction SilentlyContinue | kill -PassThru
Start-Sleep -Seconds 5
#Main Section
$Items = @(‘Archived History’,
‘Cache*’,
‘Cookies’,
‘History’,
‘Login Data’,
‘Top Sites’,
‘Visited Links’,
‘Web Data’)
$Folder = “$($env:LOCALAPPDATA)\Google\Chrome\User Data\Default”
$Items | % {
if (Test-Path “$Folder$") {
Remove-Item "$Folder$
”-Recurse -Confirm:$false -Force
}
}

Keep in mind, Chrome cannot be open to use the powershell