Any suggestions on best way to extend Collection and Cursor?


#1

I’d like to use Meteor’s datastore as a cache for resources that come from endpoints external to Meteor. I thought I could do it by creating a new class that extends Cursor and overrides the fetch(), etc.

I (think) I’m aiming to have the fetch method do something like check if a document exists in Mongo, iff not then query an endpoint specified in the original Meteor.Collection.find call (f.e. collection.find({_id: 123, _endpoint: 'http://whatever/'}) ), then if the data is found at the endpoint insert it into Mongo, then finally fetch returns the results.

So maybe I have to extend both Collection and Cursor? Any suggestions that might point me in the right direction?


[SOLVED] Is there an existing way to use Memcached instead of MongoDB as Meteor's datastore?
#2

Or perhaps the endpoint detail would defined in the constructor of the extending class. new EndpointCollection('/path/to/cats'). Yes, this would be better.

Or perhaps I should just make my own API that queries Meteor’s datastore (whichever it may be), then get data from and endpoint if it needs to. Hmmmm… I was originally aiming to do something so that the client code wouldn’t need to change at all, but with a custom API it might have to unless my custom API is identical to Collection and Cursor, wrapping the actual calls internally.