How to disable cache for a single ion-content or component?

I have a page that shows item details, and can be pushed infinitely to keep looking at new data. I need to disable the cache for this view so that it will not keep storing listeners and html for potentially a large amount of nav pushes through history.

Is there a view-cache=“false” equivalent in Ionic 2 that will prevent the component from being cached?

Thanks for any help!

Hi, you can use the ionViewDidEnter function as discribed in the documents.
ionViewDidEnter Runs when the page has fully entered and is now the active page. This event will fire, whether it was the first load or a cached page.
EDIT: I mean ionViewDidEnter not ionViewWillEnter(if that is any help…)

Thanks S.G. I’m using ionViewWillEnter and it is working fine. The issue is that ionic is continuing to cache every page as the user continues to push() new pages, which adds to memory and event listener heap. Eventually the app is taking 10 seconds to respond to events.

I need Ionic to not cache the pages after they are no longer the active page, so that the memory / event listeners heap doesn’t increase everytime. This was possible with the ion-view cache=false in v1.

Thanks!

If you don’t ever want to return to these old pages, can you achieve your goal using setRoot instead of push?

This is my user’s navigation path:
home => shelf => item1 => item2 => item3 …=> item15

They need to be able to hit back and traverse through these items again. However, the app doesn’t need all these pages to be sitting in memory with active event listeners ad nasuem. They should be able to pop() back and have the page reload its data as if it was new because it wasn’t caching the template and listeners.

Slicing the history state to only keep a max history entries also doesn’t work, because the user needs to be able to traverse back through the pages.

Is the answer that ionic does not provide support for dumping the cache of pages while keeping their history entries intact anymore?

If event listeners are your primary concern, you can set them up in ionViewWillEnter and tear them down in ionViewWillLeave. I frequently do that with subscriptions to observables. My understanding is that if you want pushed pages to be destroyed, you must explicitly pop them, although I am not positive about this.

It seems the template state that is causing all the listeners, they are all still in the digest loop, not any custom ones i’ve set.

I get that this isn’t a huge deal for apps, but for the progressive web it would seem that there should be a way to say "don’t cache this " so that its not sitting in memory just because there is a history state attached to it, but maybe i’m the crazy one here. Surely Amazon doesn’t cache every page as you click through each item page to the next, while also maintaining a history of traversing back through your navigation history.

Hi!

I have a similar problem!

I have an app that is based on tabs and I want that when I choose one of that tabs, when I return to the first one it will reprocess all that page, instead of using cached memory.

Do anyone have an idea how to do it?

Thanks

Checkout the life cycles.

ionViewWillEnter(){
// your code here
}
1 Like

Thank you for your help, but that doesn’t work.

If you have previously load one tab, when you return to that tab it will not be reloaded, and everything that you put inside ionViewWillEnter or other lify cycle method will only be processed when you click a seconde time on that tab.

1 Like

have you got any work around? i also facing same issue

You need to remove the pages from nav stack. You may refer the below discussion or search for removing pages from navigation stack.
https://forum.ionicframework.com/t/navcontroller-remove-pages-from-history-to-improve-navigation/76951