How to delete the browser cache through ruby

A

Arihan Sinha

Hi All,

I am using the below code but it seems not working for IE. ( not sure).
Could anyone please help me how to delete the cache .

I also found the code in the below location but it seems very unclear
which method I need to call etc. Can anyone please step wise tell me if
I need to use the code from
http://lazax.com/software/del_cache/del_cache.html

http://lazax.com/software/del_cache/del_cache.html

def delete_cache

@window_os_flag = RUBY_PLATFORM.downcase.include?("mswin")

#@mac_os_flag = RUBY_PLATFORM.downcase.include?("darwin")

@browser_name = page.get_eval("navigator.userAgent")

if @window_os_flag.to_s == "true"

if @browser_name.to_s =~ /IE/
puts "Test is running in window platform with browser IE"
puts
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*')
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*'),:force => true
puts
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*')
end

if @browser_name.to_s =~ /Chrome/
puts "Test is running in window platform with browser
googlechrome"
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Google/Chrome/User
Data/Default/*'),:force => true
end

if @browser_name.to_s =~ /Firefox/
puts "Test is running in window platform with browser Firefox"
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Mozilla/Firefox/Profiles/*/Cache/*'),:force
=> true
end

end

end


Cheers
A
 
D

Dhruva Sagar

[Note: parts of this message were removed to make it a legal post.]

I think it is probably a better idea to ensure that the cache expires in due
time, rather than trying to clear it programmatically.
 
A

Arihan Sinha

Dhruva said:
I think it is probably a better idea to ensure that the cache expires in
due
time, rather than trying to clear it programmatically.

Actually I am doing some performance testing by retrieving the response
time of the page without cache and with cache. So I need to delete the
cache.If anyone can help me for IE that would be great.


Cheers
Arihan
 
M

Mohit Sindhwani

Actually I am doing some performance testing by retrieving the response
time of the page without cache and with cache. So I need to delete the
cache.If anyone can help me for IE that would be great.
If your Ruby is running the client, you could try deleting the files
within the temporary files folder.

Cheers,
Mohit.
26/9/2010 | 12:49 AM.
 
C

Charles Calvert

I am using the below code but it seems not working for IE. ( not sure).
Could anyone please help me how to delete the cache .
[snip]

def delete_cache

@window_os_flag = RUBY_PLATFORM.downcase.include?("mswin")

#@mac_os_flag = RUBY_PLATFORM.downcase.include?("darwin")

@browser_name = page.get_eval("navigator.userAgent")

if @window_os_flag.to_s == "true"

if @browser_name.to_s =~ /IE/
puts "Test is running in window platform with browser IE"
puts
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*')
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*'),:force => true

It's a bad idea to delete the temporary files at the filesytem level
like that. You could cause errors in the IE instance. Instead, Take
a look at the Win32API functions that you can use for this:
<http://msdn.microsoft.com/en-us/library/aa384026(VS.85).aspx>.

You can access these functions in Ruby using the Win32API library or
the dl/win32 library, both of which are part of the Ruby stdlib.
 
A

Arihan Sinha

Charles Calvert wrote in post #955502:
I am using the below code but it seems not working for IE. ( not sure).
Could anyone please help me how to delete the cache .
[snip]

if @browser_name.to_s =~ /IE/
puts "Test is running in window platform with browser IE"
puts
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*')
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*'),:force => true

It's a bad idea to delete the temporary files at the filesytem level
like that. You could cause errors in the IE instance. Instead, Take
a look at the Win32API functions that you can use for this:
<http://msdn.microsoft.com/en-us/library/aa384026(VS.85).aspx>.

You can access these functions in Ruby using the Win32API library or
the dl/win32 library, both of which are part of the Ruby stdlib.

Hi Charles,

it seeems the whole delete_cache.rb is mentioned in this thread ( the
details code in the previous post) but its very confusing which method
need to call. So if you can highlight anything w.r.t that then it would
be great.

Regards
Arihan
 
C

Charles Calvert

Charles Calvert wrote in post #955502:
I am using the below code but it seems not working for IE. ( not sure).
Could anyone please help me how to delete the cache .
[snip]

if @browser_name.to_s =~ /IE/
puts "Test is running in window platform with browser IE"
puts
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*')
FileUtils.rm_r
Dir.glob('/Users/'+ENV['USERNAME']+'/AppData/Local/Microsoft/Windows/Temporary
Internet Files/*'),:force => true

It's a bad idea to delete the temporary files at the filesytem level
like that. You could cause errors in the IE instance. Instead, Take
a look at the Win32API functions that you can use for this:
<http://msdn.microsoft.com/en-us/library/aa384026(VS.85).aspx>.

You can access these functions in Ruby using the Win32API library or
the dl/win32 library, both of which are part of the Ruby stdlib.

it seeems the whole delete_cache.rb is mentioned in this thread ( the
details code in the previous post) but its very confusing which method
need to call. So if you can highlight anything w.r.t that then it would
be great.

You should look at the method main starting on line 122. That's the
loop that you'll need to execute.

BTW, some of the method names (e.g. get_first_info) leave something to
be desired. If you're going to use this code, even just as an
example, I'd rename those methods to something more descriptive.
 
A

Arihan Sinha

Charles Calvert wrote in post #956120:
You should look at the method main starting on line 122. That's the
loop that you'll need to execute.

BTW, some of the method names (e.g. get_first_info) leave something to
be desired. If you're going to use this code, even just as an
example, I'd rename those methods to something more descriptive.

Hi Charles,

I did in a different way. I need to call that in my script so that when
I call, the complete del_cache.rb should run. So I used the below and
its working fine.

require 'rake'
sh %{ruby lib/del_cache.rb}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top