Clearing WebView cache
<script src=...) was not working properly.
Turned out the included script file is just being cached, and I have to restart Pythonista to get the latest version. Calling
reloadmade no difference.
Looking on the net, it seems I might need to empty the shared URL cache. Could someone help me translate the following to
[[NSURLCache sharedURLCache] removeAllCachedResponses];
Or other options for ensuring that the latest script is loaded (without adding any random parts to the URL)?
Managed to convert the snippet above to:
NSURLCache = objc_util.ObjCClass('NSURLCache') url_cache = NSURLCache.sharedURLCache() url_cache.removeAllCachedResponses()
@omz, would you know of other options to clear the cache or get a fresh version of the file?
zrzka last edited by zrzka
Try to get rid of the cache completely ...
from objc_util import ObjCClass NSURLCache = ObjCClass('NSURLCache') shared_cache = NSURLCache.alloc().initWithMemoryCapacity_diskCapacity_diskPath_(0, 0, None) NSURLCache.setSharedURLCache_(shared_cache)
... it helped me quite a while ago (not in Pythonista, elsewhere). Maybe it will work for you as well. One of the three hard things in computer science - caching, naming things and off-by-one errors :)
@zrzka, thanks. Unfortunately even that did not help. Maybe there is some caching hidden in the Pythonista version of the WebView?
Have you tried appending a time to the script query?
From what i read, this will defeat caching.
@JonB, that's sure a neat way to implement the traditional cache avoidance. I was unwilling to go that route, as there are several CSS and JS files involved, and caching is not an issue in production.
omz last edited by
alert(), it will keep popping up messages even after I have closed the WebView.
Have you tried having a close() methd that loads a new page (or an empty page)into the WebView?
@JonB, thanks, now I have :-)
Tried loading an empty page (load_html) and loading an unrelated page (load_url), to no effect except that the editor freezes for a moment as the page is loading in the background.
Also tried combining the load with cache-clearing action, but no joy.
Load empty (then pause) before cache clear?
Ok, how about dynamic modification of the page after load to alter all of the script tags to append a unique identifier (time)?