是否可以清除Ionic中的视图缓存? [英] Is it possible to clear the view cache in Ionic?

查看:1399
本文介绍了是否可以清除Ionic中的视图缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发Angular / Ionic / Cordova项目,我们最近升级到了最新的Ionic beta版。从项目之前使用的版本开始,这引入了视图缓存。然而,它也引入了一个问题。

I'm currently working on a Angular/Ionic/Cordova project and we've recently upgraded to the latest Ionic beta. From the version the project was using before, this introduced the view cache. It has also however introduced an issue in doing so.

该应用程序面向客户,并且非常以数据为中心。但是,用户必须进行身份验证才能查看与其帐户关联的数据;当用户注销并登录到另一个帐户时,由于视图仍然被缓存,因此会显示最后一个帐户的视图。

The application is customer-facing and is very data-centric. A user must authenticate to view data associated with their account, currently however; when a user logs out, and logs into another account, because the view(s) are still cached they are presented with the views of the last account.

应用程序应该当用户登录时仍然缓存视图,因为它有助于使应用感觉更快,但是当用户注销时应该清除缓存。

The app should still cache the views when the user is logged in, as it helps make the app feel much quicker, but the cache should be purged when a user logs out.

设置 cache-view =false不是一个选项,因为它会完全禁用缓存。

Setting cache-view="false" is not an option, as it would completely disable the cache.

我是还尝试设置 $ ionicConfig.views.maxCache(0); ,然后回到默认值10,希望它会清除缓存这样做,但它有没有效果。

I've also tried setting $ionicConfig.views.maxCache(0); and then back to the default of 10 in the hopes that it would purge the cache in doing so, but it had no effect.

我能想到的最后一件事就是在用户登录时触发一个事件,刷新当前加载到视图中的所有数据 - 但是,这个比我觉得应该花费更多的努力。

The last thing I can think of to do is fire an event when a user logs in that refreshes all data that's currently loaded into the views - however, this would take a bit more effort than I feel it should.

有没有办法简单地清除视图缓存?

Is there a way to simply clear the view cache?

推荐答案

在app.js的状态定义中,您可以添加 cache:false 以禁用缓存(请参阅在状态提供程序中禁用缓存。或者,除非知道数据已更改,否则可以保持缓存。

In the state definition in app.js you can add cache:false to disable caching (See Disable cache within state provider in the Ionic docs. Or, you can keep caching except when you know data has changed.


  • 如果你已经在页面上,你可以这样做, $ state.go($ state.currentState,{},{reload:true})

  • 如果你处于另一个状态,想要回到通常被缓存的状态,但你想要刷新它,你可以这样做, $ ionicHistory.clearCache()。then(function(){$ state.go('app.fooState')})

  • If you're already on the page, you can do, $state.go($state.currentState, {}, {reload:true})
  • If you're on another state and want to go back to the state that is normally cached but you want it to be refreshed, you can do, $ionicHistory.clearCache().then(function(){ $state.go('app.fooState') })

注意,后者需要clearCache来返回一个promise。查看我在这个pull请求中所做的更改,并将你现在拥有的clearCache的实现与我的比较:https://github.com/driftyco/ionic/pull/3724

Note, the latter requires clearCache to return a promise. See the changes I made in this pull request and compare the implementation of clearCache that you have now with mine: https://github.com/driftyco/ionic/pull/3724

这篇关于是否可以清除Ionic中的视图缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆