poetic:aggregate-cache

v0.0.1Published 10 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

Use

MaintainCache( ParentCollection, 'parentCacheField', Child, 'childParentRelationField', function( doc ){ return calcDocValue(doc); } )

Document value calculation

The last argument calculates the value of a document. Should be a pure function, in other words, it should change any state.

How it works

On insert it calculates the value of the document and increments the parent cache. On update it removes the old value from the old parent, and adds the new value to the new parent (not optimized yet). On remove it decrements the old value from the parent cache.