Reputation: 341
[TLDR] Does CouchDB cache and reuse the results of map/reduce functions for non-modified documents?
Background info: In my Point of Sale (POS) application, all the transactions are logged and created separate document.
{ "_id": "sale_transactions_1234124", "Quanity Added": 0, "Quanity reduced": 10, "Is Discarded": "false", "saleid": "sales_523" }
{ "_id": "Purchaseorder_transactions_1234124", "Quanity Added": 5, "Quanity reduced": 0, "Is Discarded": "false" , "purchaseid": "purchase_2352"}
Whenever the inventory is modified, relevant documents are created as transactions
it is _id field. So instead of store Total sold, Quantity in hand
in Item
document, have plan to create map reduce view to retrieve every time.
Every time when I make a sale, Quantity in hand
map reduce function should be called, to check whether the quantity is greater than zero. For this approach will I encounter any performance issue, or did you recommend create Total sold, Quantity in hand
in Item document
So every time we call map reduce function, is couchdb some how cache non-modified document results and process new and modified documents, or is it process all the documents in every time?
Upvotes: 1
Views: 98
Reputation: 907
Yes CouchdDB caches your map/reduce documents. So if you query the same view multiple times Couch will give you the cached version. If additional datasets are added to the database Couch will update the view.
To see that Couch caches the views you can try to create a new view on a database with a lot of documents:
Upvotes: 0