kevinohara80 / nforce

nforce is a node.js salesforce REST API wrapper for force.com, database.com, and salesforce.com
MIT License
474 stars 167 forks source link

Add query caching option #60

Closed tehnrd closed 10 years ago

tehnrd commented 10 years ago

I am just throwing this idea out for feedback so feel free to close as neccessary if it's not applicable.

Has there been any thought given to some sort or query caching feature to prevent an excessive amount of salesforce.com API hits?

Let's say you have an app that performs a query like this alot...

org.query({ query: 'SELECT Id, Name FROM Product2' }, function(err, res) {
  //hi products
});

The response of this isn't going to change often and maybe we don't want to hit the salesforce.com API everytime. Maybe only hit it every 10 minutes or so. Perhaps a cache option like this:

org.query({cache: 60000, query: 'SELECT Id, Name FROM Product2' }, function(err, res) {
  //hi products
});

nforce will store the response in something like redis for 10 minutes and check here to see if we have already performed this query. If so return value from cache, else hit the salesforce API with the query. Different users may also get different results based on their permissions so there may also be an option to cache queries against the user who is performing the query.

Yes, this wouldn't be that hard to build yourself outside the context of nforce but I can see it being useful if built in as it would simplify the application code.

kevinohara80 commented 10 years ago

This would make a really cool plugin.

https://github.com/kevinohara80/nforce#plugins