将缓存对象存储到AngularJS的会话范围中

时间:2019-02-11 18:57:55

标签: angularjs cachefactory

我有一个示例AngularJS(1.6)应用程序,我在其中尝试测试$ cacheFactory。一切正常,但我看到每次调用Controller的构造函数时都会重新初始化缓存对象。在调用$ onChanges()方法之前,有什么方法可以检查它,例如将其存储在会话中并访问它们。

请提出建议

class MegaController {

constructor(
        $state,
      $cacheFactory) {
        'ngInject';
this.autoPaycache = $cacheFactory.get('autoPayCache') || $cacheFactory('autoPayCache'); 
)

$onChanges(changesObj) {
if(this.autoPaycache.get(this.key) === undefined){
                console.log("yes its new key");
                this.autoPaycache.put(this.key,this.autoPayAccount)
            }else{
                console.log("No its old key");
            }

}

    $onDestory() {
        console.log('clean up');
        this.autoPaycache.destroy();
    }

0 个答案:

没有答案