2

I'm building a Cordova app that presents CRUD operations around a list of Tickets. The home page presents the list and you can click on any list item for more details about a specific Ticket.

The home page is reached at / and presents a tickets template. The ticket page is reached at /ticket/:_id and presents a ticket template.

The / route subscribes to all the tickets related to the current user (pagination coming soon). I'm assuming this data is cached client-side in minimongo.

When the user clicks to see more about a ticket, I've tried fetching new data via Tickets.findOne(Router.current().params._id). It works if I add a single ticket subscription to this route. It does not work if I get rid of the subscription.

This doesn't make a lot of sense because the initial tickets subscription should cache all the visible tickets client-side in minimongo. When doing a Tickets.findOne(Router.current().params._id) -- shouldn't Meteor look to minimongo for that data without needing a new subscription?

I'm using GroundDB to ground collections and methods even if the app is offline. It works, but does not address subscriptions across routes.

Any suggestions on how best to cache data across routes to make the app snappy and reduce DB trips?

Gaurav
  • 974
  • 9
  • 13

1 Answers1

2

It sounds like you need to use subs-manager.

Why?

When you are subscribing inside a Tracker.autorun computation, all the subscriptions started on the previous computation will be stopped.

Iron Router runs all subscriptions inside a Tracker.autorun computation, so this will affect Iron Router too: when you navigate to a new route, all the previous subscriptions will be stopped. The user will have to wait a bit even if they've visited that route previously. That's an UX issue.

Also, this will force the Meteor server to resend data you already had in the client. It will waste your server's CPU and network bandwidth.

Solution

Subscriptions Manager caches your subscriptions and runs all the subscriptions that have been cached when a route is changed. This means that when switching between routes, the user will no longer have to wait. Also, Meteor won't need to re-send data that's already in the client.

In technical terms, Subscriptions Manager runs it's own Tracker.autorun computation internally. It does not interfere with Iron Router and works independently.

Subscriptions Manager does not cache your individual data. It tells Meteor to cache the whole subscription. So, your data will get updated in the background as usual.

Community
  • 1
  • 1
JeremyK
  • 3,240
  • 1
  • 11
  • 24