4

I have a Phonegap App where I need at some point to remove the html cache because I have updated the images in my app.

I have tried this :

[[NSURLCache sharedURLCache] removeAllCachedResponses];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];

Called in a plugin via javascript, the i do :

location.reload( true )

But I still see the same image that seems to be cached.

Is there another way of doing this ? I can tell the user to quit the app and kill it and relaunch it after.

Thanks !!

arlg
  • 1,128
  • 3
  • 16
  • 34
  • can you Please tell us which version of CORDOVA you are using? We are having issue that UIWEBVIEW clears the Caches as soon as application exits. So when I run the application Next Time With WIFI off. No image appears. [Please see our query Here](http://stackoverflow.com/questions/19446317/ios-phonegap-application-ignoring-cache-headers-and-not-caching-images) – abksharma Oct 21 '13 at 10:17
  • I think it's the ios behavior to clean the memory once the app is shut down. – arlg Nov 20 '13 at 21:39

4 Answers4

0

What you can try is to completely remove the cache directory in your app for example at the very first start of the app

oiledCode
  • 8,589
  • 6
  • 43
  • 59
0

You Can have URL versioning system for images. As I have mentioned here.

http://www.abksharma.in/2013/10/caching-using-javascript-versioning.html

request images with below URL param.

http://s.wordpress.org/screenshots/3.5/ss5-dfw.gif?1
http://web-sniffer.net/
Above is truly cached image with below headers

For DATA we can Use below.

How to Enable ajax request caching for semi dynamic data (ie JSON)?

Community
  • 1
  • 1
abksharma
  • 576
  • 7
  • 26
0

You can simply solve this by add timestamp after the url.Then you can make sure that the url you request everytime is different.

Just like this:http://www.demo.com/xxxx?t=timestamp.

The javascript code just like this:

var url = 'xxxx/xxx?timestamp=' + Date.now();
NSKevin
  • 564
  • 8
  • 20
0

None of these helped me.

I was afraid I was going to have to resort to generating unique file names and cleaning up when done.

This worked great.

<img src="data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAYAAADE6YVjAeu
... snip data ....
YII=">

How to display Base64 images in HTML?

Community
  • 1
  • 1
Ed of the Mountain
  • 5,219
  • 4
  • 46
  • 54