当使用角度缓存没有任何优势,使用的角度LocalStorageModule? [英] When using angular-cache is there any advantage to using the Angular LocalStorageModule?

查看:365
本文介绍了当使用角度缓存没有任何优势,使用的角度LocalStorageModule?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

角高速缓存可以设置如下:

The angular-cache can be set up like this:

app.service('myService', function ($angularCacheFactory) {

    // This cache will sync itself with localStorage if it exists, otherwise it won't. Every time the
    // browser loads this app, this cache will attempt to initialize itself with any data it had
    // already saved to localStorage (or sessionStorage if you used that).
    var myAwesomeCache = $angularCacheFactory('myAwesomeCache', {
        maxAge: 900000, // Items added to this cache expire after 15 minutes.
        cacheFlushInterval: 3600000, // This cache will clear itself every hour.
        deleteOnExpire: 'aggressive', // Items will be deleted from this cache right when they expire.
        storageMode: 'localStorage' // This cache will sync itself with `localStorage`.
    });
});

据我了解,如果storageMode设置为localStorage的',那么它处理备份到localStorage的本身。

From what I understand if the storageMode is set to 'localStorage' then it handles backing up to localstorage itself.

我已经使用其他东西的角度LocalStorageModule。

I am already using the angular LocalStorageModule for other things.

有没有我建立一个localStoragePolyfill并使用LocalStorageModule什么优势?

Is there any advantage in me setting up a localStoragePolyfill and using the LocalStorageModule?

推荐答案

我会说,这是最强大的用法缓存合作localStorage的可以在这里找到: 。把(键,值,选项)

I would say, that the most powerfull usage of the Cache cooperating with LocalStorage could be found here: .put(key, value, options)

正如你所看到的,第三个参数是的选项,设置该键值对,不可以整个缓存实例。

As you can see, the third parameter, is the options, the setting for this key and value pair, not for the whole cache instance.

因此​​,我们可以这样调用

So we can call it like this

myAwesomeCache.put('someItem'
  , 'someValue'
  , { storageMode: 'localStorage', storageImpl: myLocalStoragePolyfill });

其中, myLocalStoragePolyfill 是我们对本地存储的包装?或者我们可以只使用内置的处理程序,并通过它像 {storageMode:localStorage的'}

where myLocalStoragePolyfill is our wrapper of the local storage? or we can just use the built-in handler and pass it like { storageMode: 'localStorage' }

所以,有这个,什么是真正的优势在哪里?我们可以缓存一些很稳定的,恒定的设置(如果有的话)。一个例子可以是一些元数据,该应用程序复杂的配置,它可以几乎不发生变化。

So, having this, what is the real advantage? we can cache some really stable, constant settings (if there are any). An example could be some Metadata, complex configuration for the application, which can hardly change.

因此​​,如果,我们知道,那的东西几乎是静态,我们有简单的方法,如何使用标准的缓存提高peformance ...

So, in case, that we know, that something is almost static, we do have simple way how to use standard cache, while improving peformance...

注:本地存储是不一样的内存缓存。它存储对象的JSON类型。没有办法!只是字符串重新presentation

这篇关于当使用角度缓存没有任何优势,使用的角度LocalStorageModule?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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