Copyright © TIBCO Software Inc. All Rights Reserved


Chapter 8 Cache Modes and Project Design : Working With Cache Modes

Working With Cache Modes
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:
This section describes the cache modes available in more detail, and explains how to use them appropriately.
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.
See Loading Cache Only Objects into the Rete Network for important information about how use of the Cache Only mode affects your project design.
Cache Modes are Set on Individual Entities to Tune Performance
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.
See Concept Relationships for more details about the relationships between concepts.
Cache Plus Memory — For Constants and Less Changeable Objects
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:
Declaration (Scope): Customer
Condition: Customer.age < 20
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.
Appropriate locking in complex projects that use concurrency features can be difficult with Cache Plus Memory.
Memory Only — Useful for Stateless Entities
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.
This mode is typically used for static reference data that can be created in the rule functions on startup.
Memory Only mode can also be used for transient utility entities that created and deleted within a single processing, and are not needed across RTC cycles.
Entities configured in this mode do not persist objects to the cluster and correspondingly the objects are not recovered from the cluster.
This cache mode works the same as the In Memory object management option (but is set for individual objects).
Cache Only Mode
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.
The Cache Only mode is stateless between RTCs. You must explicitly load the objects needed by rules in an RTC, and you must ensure proper locking is used (see Using Locks to Ensure Data Integrity Within and Across Agents).
Various functions are available for loading the entities into the Rete network. They are generally used in an event preprocessor. See Loading Cache Only Objects into the Rete Network for more details.

Copyright © TIBCO Software Inc. All Rights Reserved