Can Meteor's Appcache also store database data?

旧城冷巷雨未停 提交于 2019-12-11 16:33:53

问题


With the latest Meteor version 0.5.9 I've been experimenting with the appcache package, and really like its functionality.

I used meteor create --example leaderboard and then meteor add appcacheto test out the behaviour, and the page even loads when the server is not running at all! Super cool!

However, the database does not seem to be cached? When the server is not running

Players.find().fetch()

returns

[]

This is quite a showstopper for me, as I'm making a notes app where the notes need to be available offline as well. Am I missing something or is there an alternative method of getting database data when offline?


回答1:


The appcache package doesn't cache your data. See the docs:

The appcache package stores the static parts of a Meteor application (the client side Javascript, HTML, CSS, and images) in the browser's application cache.

[...]

(Note however that the appcache package by itself doesn't make data available offline: in an application loaded offline, a Meteor Collection will appear to be empty in the client until the Internet becomes available and the browser is able to establish a livedata connection).

At this point the appcache package is purely meant to improve loading speed of your app by caching static resources. See the meteor wiki:

The appcache package is only designed to cache static resources. As an "application" cache, it caches the resources needed by the application, including the HTML, CSS, Javascript and files published in the public/ directory.




回答2:


Look at the Ground:DB Package for this use. This package makes client side caches of subscribed collections.

https://atmospherejs.com/ground/db

Example of a collection that will get populated by Meteor subscriptions (subscribe call required separately)

localCollection = new Ground.Collection('mongoName');

Example of disconnected Collection (so you have to populate it yourself)

disconnectedCollection = new Ground.Collection('localName', {connection:null} );


来源:https://stackoverflow.com/questions/15478597/can-meteors-appcache-also-store-database-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!