Yannis
Yannis

Reputation: 95

Is meteor keeping cache for each "publish"

I'm using Iron Router (with RouteControllers) and I'd like to know if meteor keep cache for "publishes" when page (url) change.

Example : I want use meteor for a cooking site, so I've a section with a BIG list of recipes, and I can filter this list (by theme, preparation time, etc.). So, potentially, there will be a lot of different lists.

(This is a use case but my question can be valid for classic schema : a user visits a recipe detail page, and go away... does meteor clean cache for this subscription on server (which published the recipe datas) ?)

If I use subscriptions, does meteor keep cache when I change filter information ? And if not, how to do that without keep cache on local user database (and on server) for each request use can make ?

Sorry, I'm a beginner in meteor and it's a little confused for me. When I read documentation about meteor and publish/subscribes, I think that my app usage will increase memory excessively...

Upvotes: 0

Views: 568

Answers (2)

Michel Floyd
Michel Floyd

Reputation: 20256

afaik the cache is client-side, in minimongo. The publication on the server isn't actually used until you subscribe to it on the client. i.e.:

Meteor.publish('allRecipes',function(){
  return Recipes.find();
});

Doesn't do anything by itself. A client subscription needs to refer to it.

If your collection of recipes is very large and you don't want to have a lot of network overhead to move it all to the client, then you can implement server-side search in your subscription, for example with https://atmospherejs.com/meteorhacks/search-source

Upvotes: 0

Kyll
Kyll

Reputation: 7151

There is multiple scenarios to take into consideration:

  1. The user closes the page and re-opens it, or refreshes.
    In that case, no subscription whatsoever is natively kept.

  2. The user changes page with a router (no reload or page closing), templates are destroyed

    • If the publication is done inside the router controls, it's generally cancelled (not kept) on page change. I think this is valid for both iron:router and meteorhacks:flow-router.
    • If the publication is done inside the template control, it is cancelled on destruction.
    • Else if it is done outside these pre-defined controls then the subscription is not cancelled.

You will need to adapt to these behaviours. If you want, for example, to remember the subscriptions across router pages, you will need to store them externally and control them in your own way.

Upvotes: 1

Related Questions