# Clear cache when change between tabs

**URL:** <https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828>\
**Category:** ionic-v3\
**Created:** [July 12, 2017, 7:19am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828 "2017-07-12T07:19:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![liuya891012](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@liuya891012](https://forum.ionicframework.com/u/liuya891012)\
**Post date:** [July 12, 2017, 7:19am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/1 "2017-07-12T07:19:54Z")

</div>

Hi!

I’m working with Ionic 2, and I want to clear cache when I change a tab. Now, if I do something in one tab and change something, when I change the tab and then comeback, the tab will be in the same place.

Thanks

---

<div class="post-metadata">

**Author:** ![cherry](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cherry/32/149370_2.png) [@cherry](https://forum.ionicframework.com/u/cherry)\
**Post date:** [July 13, 2017, 4:25am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/2 "2017-07-13T04:25:33Z")

</div>

This should do the trick.

> ngAfterViewInit() {  
> $ionicHistory.clearCache();  
> }

Just paste this code in your pages .ts file **‘ngAfterViewInit’** basicly means this code will be executed when you leave the page.

---

<div class="post-metadata">

**Author:** ![liuya891012](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@liuya891012](https://forum.ionicframework.com/u/liuya891012)\
**Post date:** [July 13, 2017, 4:38am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/3 "2017-07-13T04:38:46Z")

</div>

thanks，but `$ionicHistory` work in ionic1,ionic2 do not have `$ionicHistory`

---

<div class="post-metadata">

**Author:** ![cherry](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cherry/32/149370_2.png) [@cherry](https://forum.ionicframework.com/u/cherry)\
**Post date:** [July 13, 2017, 4:43am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/4 "2017-07-13T04:43:29Z")

</div>

Then you could use navPop, it should remove the page from the cache then.

> this.navCtrl.pop();

---

<div class="post-metadata">

**Author:** ![liuya891012](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@liuya891012](https://forum.ionicframework.com/u/liuya891012)\
**Post date:** [July 13, 2017, 4:57am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/5 "2017-07-13T04:57:59Z")

</div>

changing between tabs

![image](https://global.discourse-cdn.com/ionicframework/original/3X/b/f/bf0c53345ee783e3b7d80c628fd6f072f8e3cbb9.png)

---

<div class="post-metadata">

**Author:** ![cherry](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/cherry/32/149370_2.png) [@cherry](https://forum.ionicframework.com/u/cherry)\
**Post date:** [July 13, 2017, 5:02am UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/6 "2017-07-13T05:02:04Z")

</div>

I don’t know what you mean, but you can add this to your pages if you want to clear their cache after you viewed them.

> ngAfterViewInit() {  
> this.navCtrl.pop();  
> }

---

<div class="post-metadata">

**Author:** ![tanogalegok](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/tanogalegok/32/112889_2.png) [@tanogalegok](https://forum.ionicframework.com/u/tanogalegok)\
**Post date:** [August 31, 2017, 7:16pm UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/7 "2017-08-31T19:16:44Z")

</div>

Hey @cherry, what @liuya891012 means is that all the Tabs are placed in just one Navigation page for the NavController… so there’s no way to do what you’re saying. Anyone came up with a correct answer for this problem?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 31, 2017, 8:47pm UTC](https://forum.ionicframework.com/t/clear-cache-when-change-between-tabs/97828/8 "2017-08-31T20:47:09Z")

</div>

> [@tanogalegok](#):
>
> Anyone came up with a correct answer for this problem?

Can’t say it’s a correct answer, but my answer is that this is _not_ a problem. It is the way users expect tabs to behave, and I consider it flawed design to make them do otherwise.

Let’s say the currently selected tab is tab A. I expect clicking on tab B and then tab A again to put me in the exact same position I am right now. Don’t break that UX contract.
