Friday, December 15, 2017

#1 2012-08-02 12:17:10 pm

deanshavit
Member
Registered: 2005-07-03
Posts: 125

Web View Quandry - Prefer "Live" version over "Cached" version

Hi,

I am updating an AppleScript Studio (probably for the last time) and would like to include a web view, or webview.

So I added the following code:

Applescript:

on urlGet()
   set theURL to "[url]http://accounts.myserver.com/~[/url]" & myid & "/Updates/myimage.jpg" as text
       
       try
           set newString to (call method "stringByAddingPercentEscapesUsingEncoding:" of theURL with parameter 30)
           set URLWithString to call method "URLWithString:" of class "NSURL" with parameter newString
           set requestWithURL to call method "requestWithURL:" of class "NSURLRequest" with parameter URLWithString
           set mainFrame to call method "mainFrame" of webView
           call method "loadRequest:" of mainFrame with parameter requestWithURL
   on error theError
   end try
end urlGet

This works very well, except that if the image is changed on the server, the web view will always display the cached copy located in ~/Library/Caches/com.mycompany.myapp/Cache.db

If I manually clear the cache, the image updates properly

How do I change my code so that it prefers the "live" copy to the cached copy, unless, of course, the server is unreachable?

Last edited by deanshavit (2012-08-02 12:31:16 pm)

Offline

 

#2 2012-08-02 06:58:56 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 5199

Re: Web View Quandry - Prefer "Live" version over "Cached" version

I can't help with your ASStudio code, but you're calling +requestWithURL:, and you need to call +requestWithURL:cachePolicy:timeoutInterval:. The cachePolicy parameter is the key for what you want.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)