[Solved] Subscription Cache or Local Storage or Other Pattern?

Hey guys. So this is the scenario:

I have a Documents collection. I subscribe for a list of them, and when one of the list is clicked I subscribe to that particular document with _id, so I have the data for the Detail View.

My problem with this, is that I want to reuse those components, and have a “Search” feature.
Search will search for documents in a endpoint in the web, HTTP.get. I do that with publications and storing results in a local collection SearchDocuments.

When I want to see the detail view, I would like to keep that document in the local SearchDocuments collection.
Changing the route destroys the component. SearchDocument disappear, and subscription stops.

What would be the best practice for this scenario?

-> list view:
- subscribe ‘allDocs’
if clicking in one doc, Doc View:
- subscribe ‘oneDoc’, _id

-> search view: query?

  • search query in API HTTP.get
  • subscribe to ‘search’ with query. Publication stores in SearchCollection created in client.
  • Docs results are in SearchCollection only in Client.

if clicking in one doc of SearchCollection (results), Doc View:
- subscribe ‘oneDoc’, _id (will not find in the DB since docs came from a search in HTTP.get)
* SHOULD I? 1) HTTP.get only that document? (API /docs/id will bring only that doc back again from the web)
2) Keep that clicked doc somewhere in a local storage? and pass it to the Detail View
3) Try to keep the subscription alive after route changes?

Hope is somehow clear the scenario :smile:

You need a subscription manager! This one is pretty good: https://github.com/ccorcos/meteor-subs-cache

Qualia will also hopefully be open-sourcing our internal subscription manager soon.


Looks like a nice package. I got bored o googling, so wrote a bit my own cache :slight_smile: Working well, but this package has more powerfull features!

Cheers mate!