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

IMHO, you can’t alternate dynamically.
But in my app, I have the exact same case and I make use of this strategy: using a $cacheFactory (from Angular) as intermediate between both views (list and detail).

=>
On the list controller I have a function call showItem(itemId).
What I do first is to add all the list data, (let’s say $scope.myList) to the cache.
On the show page, when I edit something, I retrieve the corresponding item from the cache with the specific itemId and mutate it.
Now, when going back to my list view, I strictly don’t want to make an ajax call to refresh data (it’s the goal of the pull-to-refresh IMO and moreover, I would lose the scroll position, bad !), so… I use the cache values ! Basically, a simple conditional is: “If there’re data in cache, display them. Otherwise, load from database”.

You would tell me: wow you keep all the data in memory, bad !
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 ! :wink:

What I do is that I manually remove all data in cache (to force a refresh) when I want according to the conditional.
I remove it when I click on any ion-tab, through the on-select attribute, or when I select some filters (buttons) near to my list to refresh the whole list.

Hope that helps :wink: => it’s just about a good algorithm :wink: in TDD :wink:

3 Likes