Ionic Beta14: how to clean the Cache for a specific view?

@Mik378 you can dynamically clear cache using $ionicHistory.clearCache(); but as it was defined to cache this view, the controller doesn’t run again.

I agree when you say :

But the point is the cached view already caches the $scope values (in order to repopulate them), therefore, as being simple references, it’s not such a memory waste !

and

So to sum up, yes Ionic thinks about this case wink since you can update an EXISTING cached view through those events.
Better performance than “cleaning” them and recreate them.

but if you force $ionicHistory.clearCache(), controller shouldn’t be runned again?

Had a similar problem as OP and cache: false didn’t work for me at all in 1.0.0-beta14. I tried using $broadcast events but that didn’t work as well. In the end I used a similar method to what @Foxandxss proposed. Thx!

+1 guess i’ll be doing the same as @Foxandxss as well

Great Idea Collin…

I instantiated one of my route state with cache: false then from a logical navigation I manipulated the state as

$state.go ('state.name' , {}, {cache: true});

It perfectly worked.
Thanks for your idea.

1 Like

hi @DigitalIQ
how are u setting the cache: true or false $state.go (‘state.name’ , {}, {cache: true});, when you are going back with the back button?

thanks

1 Like

@Delfins @mhartington
This is how I got it to work. Minimal effort and I think the most Ionic way. I created a pull request with a minor tweak to return a promise from $ionicHistory.clearCache():

4 Likes

Wonderful @kiteboarder . Thanks very very much!

Thanks @kiteboarder!

Thanks @kiteboarder I finally found the best way to clear the cache of a cached view. Big Thanks.

@Mik378 Your approach sounds to me as a beginner very plausible, but I can’t translate it into action. Could you please give a short code example?

I didn’t find anything in the docs to update a cached view on a specific event. For me it looks like having two options: caching a view or not. But I just want to update the cashed view only if I add/edit or delete an item of the view.
Thanks for your help!

There is still no solution for this old issue: https://github.com/driftyco/ionic/issues/3884

Unfortunately, it looks like there’s a bug when hydrating them from the cache, though, in regards to their $stateParams. They seem to retain their initial values when the views are first instantiated, regardless of what is sent later, at least in certain circumstances. It just doesn’t seem like that’s the intended behavior.

I can’t make it work like that. when I back to this view, it still doesn’t cache :frowning:

I have a question, whenever we perform data manipulation like add or edit a value can’t we just reload that particular view using simpler function like window.reload() provided by javascript so that the view makes a call to the server for that particular view only based on the code we have written for that particular section ?