Cache Expensive Resources in Rules

In Rules you can store expensive resources using the global object. The global object survives individual execution, so you can reuse things stored there instead of creating them every time a Rule is run. However, the Rules environment can be recycled at any time so your code must always check that global contains what you expect.

This example shows how to use the global object to keep a MongoDB connection: