Can i disable view caching? I need my view to be up to date when the user hits the “back” button. I can update date but the view wont update.
Example: First page: List of tasks Second page: Task
I enter the list of tasks page, get the tasks from the database and list them. I show the user which task is done and which is not (with a special css class)
When the user taps a task he is redirected to a task page. There he can update the task to done. But when he goes back the tasks list will not be updated.
How can i make this happen?
Use http://ionicframework.com/docs/v2/api/components/nav/NavController/ lifecycle callbacks to get (most probable from service/provider) updated tasks list. You can make call in ionViewDidEnter for example.
The problem is that the view doesn’t refresh with the model it still cached
Any updates on this? My images are also still cached no matter in which lifecycle ill try to update them.
use ionViewDidEnter, it gots called on pop() too
That does effect nothing!
The image is cached and uses the cached image not the url.
SO it doesnt do anything. I can update the uri 10000 times if i want. It will always use the same cached image because the cached image always have the same name as the one from the url.
And if i would do a workaround with always send a differend name after the img got updated on server this would cause a fuc*ing full cache of my app with 1000 same images but a different name. Because every time the browser couldnt find the img name in the cache it would download the img from server no matter if its a different one or not.
The other way is to send Headers to stop the browser from caching but this doesnt seems to work on device for me.
The best way would be to disable the whole application form caching but i really dont know if that is possibile.
oh well… if the problem it the browser caching images then just create a filter that change the image url from:
where the number is the unix timestamp
Thats a bad workaround for me because im spaming the cache with images. Cause in my app pictures get called way to often and every time they gettin called they will be downloaded new to the cache.
then, server side, its the only way to go
Ok and how could i do it serverside?
Can you explain exactly what you’re doing? @badpenguin’s answer is generally the way to go. It’s confusing because you say you don’t want to cache the images, but then when he offers you a solution you say you need to cache the images.
Do you have a code example or anything? The original post was about just data, which ionViewDidEnter does solve. images are a different story. Do you have a code example or anything? You may want to create a new post specifically about images.
To understand better for you guys:
At the moment it does the following:
IMG -> get resource from server url -> cache the image -> user updates image on server -> img does not get updated
To get Updated i need to add a Unix Timestamp.
With that unix timestamp i get the following:
Img -> get resource of the server url -> cache image with timestamp -> user updates image -> ionic cant find image in cache -> downloads new image
And here is the problem with that timestamp version it downloads an downloads the same image again and again no matter if its another or the same one because the timestamp. So every second it downloads the image because of the timestamp. This is bad cause it trashes my cache way to much.
And this is the fact why i dont wont to cache because without cache it doesnt download the picture and always get it directly from the server and that would slove also my problem because it would update the image the same time it changes.
Okay, I’m getting a little better picture here, what I’m wondering is, can you append/update the timestamp only if the user updates the image? Or alternatively don’t download the image every second, only download it when the user changes the image on the server? Also if you want cache disabled you could try something like this? https://github.com/koenoe/cordova-disable-http-cache
Hard to know exactly what to do without the exact use case, but this might be a case for sockets.io. When a user updates an image, that even is sent to the server, then everyone subscribing to it gets the updated image. Then you could get the image only after an update instead of every second.
Ill try both solutions you mentioned here and report the result here
How do i use this? https://github.com/koenoe/cordova-disable-http-cache
there is no documentation about? Do i only need to install it or something?
Looking at the code it looks like yes you just install it. It looks like it takes the webview cordova uses and just disables the cache. So as long as you have that installed, the browser cordova uses should have no cache. I haven’t tested it or anything, but it’s worth a shot.
Honestly though just to save on server resources if you try to release this to a large audience you may be better off going the other route.