用角度缓存mat table数据源数据 [英] Caching mat table datasource data in angular

查看:50
本文介绍了用角度缓存mat table数据源数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在有角度的应用程序中缓存数据,并避免太频繁地从服务器获取数据.

I want to cache data in an angular application, and avoid fetching data from the server too often.

数据显示在材料设计表(数据源)中.

The data is displayed in a material design table (datasource).

我已经阅读了一些建议使用 RxJS publishReplay 的博客.>以及 RefCount shareReplay 来实现缓存.

I have read some blogs that suggest using RxJS's publishReplay along with RefCount, or shareReplay, to implement caching.

但是,据我了解,这意味着缓存的数据存储在RAM中.当要保存大量数据时,这是一个好策略吗?还是我应该使用浏览器的本地存储之类的其他东西?

However, as far as I understand, this means that the cached data is stored in RAM. Is this a good strategy when there is a lot of data to be saved, or should I use something else like the browser's local storage?

在Angular中如何管理缓存是否有任何成语?建议将数据库记录保存在高速缓存(约几百行)中的方法是什么?

Is there any idiom on how to manage cache in Angular? What is the recommended approach for saving records of a database in a cache (~ hundreds of lines) ?

谢谢

推荐答案

^^您有多种选择.

  • You can do it with a custom cache in the service (https://stackoverflow.com/a/60190745/1974681). With this approach when you reload your app, the caché is refreshed too.

您可以使用localStorage或sessionStorage.在这种情况下,缓存不会在应用重新加载时刷新( https://alligator.io/js/introduction-localstorage-sessionstorage/).最后,浏览器存储也使用RAM.

You could use localStorage or sessionStorage. In that case the cache will not be refreshed on app reload (https://alligator.io/js/introduction-localstorage-sessionstorage/). In the end, browser storage uses RAM too.

localStorage和sessionStorage可以完成完全相同的工作并具有相同的API,但是使用sessionStorage时,数据仅保留到关闭窗口或选项卡之前,而使用localStorage时,数据将一直保留到用户手动清除浏览器缓存或直到您的网络应用会清除数据.

localStorage and sessionStorage accomplish the exact same thing and have the same API, but with sessionStorage the data is persisted only until the window or tab is closed, while with localStorage the data is persisted until the user manually clears the browser cache or until your web app clears the data.

  • 您可以寻求更复杂的解决方案,例如 Orbitjs ,就像拥有数据库一样在浏览器中,您可以脱机工作(非常酷)

  • You can go for more complex solutions like Orbitjs, which is like having a database in the browser and you can work offline (very cool)

    我希望能有所帮助!

    这篇关于用角度缓存mat table数据源数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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