As explained in Between Cache and Rete Network: Cache Modes, with Cache OM, you can keep memory objects in the cache or Rete network using the following cache modes:
The Rete network consumes a large amount of the available memory in the JVM. You can use cache modes to tune the performance of your application, and reduce its footprint in memory.
You set cache modes at the level of individual entity types in your project. This fine granularity allows you to tune performance and memory usage based on the size and usage of the concepts, scorecards, and events in your project ontology.
For example, you can use the Memory Only mode so that frequently used stateless entities are kept in memory (and are not cached). Objects kept in memory are highly available to the application.
Using Cache Only mode reduces the memory footprint. However, you must explicitly load the objects (in rules or rule functions) so they are available to the Rete network.
With the cache plus memory setting (Cache+Memory), the entity objects are serialized and are always available in cache. There is one object in the cache (in a logical sense), and any number of references (handles) to that object in each JVM. References to the entities are tracked in the working memory so they can be deserialized and retrieved from the cache when needed by the engine.
The agent’s working memory is used to store the Rete network for the loaded rules. The inference agent does not store the actual object. It relies on the object management layer to load the objects on demand from the backing store. For example, consider a rule of this form:
If the cache mode is Cache plus Memory, then working memory stores handles to all customers, including those whose age is greater than 20. The customer objects for customers whose age is less than 20 are deserialized and retrieved from cache when the rule condition is evaluated, in order to process the rule.
Because a Rete network is so large, the references themselves can consume large amounts of memory. To reduce the memory footprint, it is recommended that you use the Cache Only mode for most entity types.
In addition, the Cache Only mode is more straightforward to use as there is less to synchronize in a multi-agent environment when the Rete network is flushed after each RTC.
When you select Memory Only mode for an entity type, instances of that entity are available only in the engine’s local JVM memory only. These entities and their properties are not recoverable, or clustered or shared. For this reason, it is recommended that you use this mode for stateless entities only.
As with the Cache plus Memory mode, when you choose the Cache Only mode for selected entities, the entity objects are serialized and are always available in cache. The difference is that at the end of the RTC, the objects and their references are removed from the Rete network, thus freeing memory.