# Clearing the View cache when loading an old page

**URL:** <https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555>\
**Category:** ionic-v3\
**Created:** [June 9, 2017, 1:27am UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555 "2017-06-09T01:27:36Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 1:27am UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/1 "2017-06-09T01:27:36Z")

</div>

when I upload a new photo to my App, I want the user to move to the photos Page (in case if the user already opened it before, all old photos are loaded), and to refresh the cached view so that the new photo is downloaded. I’m trying to do this via but it doesn’t work. I don’t want to use pop() because then the pages start to jump. Any advice on how to do this, will be greatly appreciated!

```auto
  ionViewCanLeave() {
    this.navCtrl.setRoot(OldPage);
  }

```

---

<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:** [June 9, 2017, 3:02am UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/2 "2017-06-09T03:02:53Z")

</div>

> [@dimitri320](#):
>
> refresh the cached view

This is not an idiomatic way of thinking in an Angular app. You should not concern yourself with refreshing views. Templates display things in response to bound values of properties in their associated controller. Update the property in the controller and the template will automatically do what is desired.

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 3:38pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/3 "2017-06-09T15:38:25Z")

</div>

> [@rapropos](#):
>
> automatically

How can I update it please? Many thanks for your help here!!

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [June 9, 2017, 3:55pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/4 "2017-06-09T15:55:11Z")

</div>

Won’t be able to help unless you show how you currently load the photos.

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 4:10pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/5 "2017-06-09T16:10:53Z")

</div>

Sure, here is the code. I’ve tried to also call this method from the `controller` (doesn’t refresh the view) and from `ionViewWillEnter` (same, doesn’t refersh the view). Many thanks!

```auto
  ngOnInit() {
    this.phoneStorage.SQLStorageGet('UID').then((resultSellerID) => {
      this.sellerID = 'ID';
      firebase.database().ref('/seller/' + this.ID).orderByKey().limitToFirst(6).once('value', (snapshot) => {
        snapshot.forEach(snap => {
          if(this.counter <= 4) { //2
            let temp = {
              photo: snap.val().photo
            }
            this.object.push(temp);
            this.counter++;
            this.counter2++;
            return false;
          } else {
            this.startListingID = snap.val().listingID;
          }
        }), (this.counter === 0 && this.counter2 === 0) ? this.empty = true : this.empty = false;
      }).catch((error) => { console.log("Firebase Once Error: " + JSON.stringify(error)) });
    });
  }

```

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [June 9, 2017, 4:14pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/6 "2017-06-09T16:14:27Z")

</div>

And where and how do you display

> [@dimitri320](#):
>
> this.object

then?

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 4:18pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/7 "2017-06-09T16:18:17Z")

</div>

```auto
<ion-content>

  <div *ngFor="let i of object" class="listing" >
    <ion-slides pager="true" spaceBetween="20px" class="slides">
      <ion-slide *ngIf="i.photo0" class="slide">
        <ion-spinner name="bubbles" *ngIf="!i.load.photo0"></ion-spinner>
        <div class="divOuterPhoto"><div (click)="navigateToListing(i.listingID)" class="divPhoto"><img [hidden]="!i.load.photo0" (load)="i.load.photo0=true" [src]="i.photo0" class="slidePhoto"></div></div>
      </ion-slide>
    </ion-slides>
  </div>

  <ion-infinite-scroll (ionInfinite)="doInfinite($event)">
    <ion-infinite-scroll-content class="infiniteScroll" loadingSpinner="bubbles" loadingText="Loading more..."></ion-infinite-scroll-content>
  </ion-infinite-scroll>

</ion-content>

```

---

<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:** [June 9, 2017, 7:26pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/8 "2017-06-09T19:26:10Z")

</div>

If I am reading this correctly, there are N `<ion-slides>` elements, each containing one `<ion-slide>`. That seems strange. I thought generally one has one `<ion-slides>` element containing N `<ion-slide>` elements.

Aside from that, I don’t see how any of these properties that hang off of `load` that determine what is shown when are being set.

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 7:32pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/9 "2017-06-09T19:32:05Z")

</div>

I’ve got a system similar to Instagram, with multiple photos per post, but I’ve deleted the repeated code to unclutter it.

I’ve already solved this with a workaround, via a messaging say please refresh to display your latest photo. Words great! Thanks!

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [June 9, 2017, 7:44pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/10 "2017-06-09T19:44:55Z")

</div>

> [@dimitri320](#):
>
> I’ve already solved this with a workaround, via a messaging say please refresh to display your latest photo. Words great! Thanks!

That is not really a solution but avoiding the problem 😛

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 9, 2017, 11:41pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/11 "2017-06-09T23:41:33Z")

</div>

Yes, I agree, and this is a VERY BAD method for avoiding this problem… If you come up with something better, please let me know.

---

<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:** [June 10, 2017, 2:49am UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/12 "2017-06-10T02:49:57Z")

</div>

> [@dimitri320](#):
>
> If you come up with something better, please let me know.

Please post something minimal and complete that people can use to reproduce the situation. Very frequently people post things that oversimplify to the extent that the underlying issue is not reproducible given the provided information.

---

<div class="post-metadata">

**Author:** ![dimitri320](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/dimitri320/32/116022_2.png) [@dimitri320](https://forum.ionicframework.com/u/dimitri320)\
**Post date:** [June 12, 2017, 7:17pm UTC](https://forum.ionicframework.com/t/clearing-the-view-cache-when-loading-an-old-page/93555/13 "2017-06-12T19:17:43Z")

</div>

I actually don’t have a solution for this yet. The way I’m temporarily solving this is by passing a check variable set to TRUE, which displays a button (via the hidden attribute) which says “you have new photos, click here to refresh view”.
