Cache Loader Write-through and Bulk Operations
To simplify using backend datastores with GridCache, it’s sometimes desirable to add a means for supporting the store and remove methods on the loader rather than just supporting it purely as a data fetching mechanism. It’s also sometimes desirable to be able to use such methods in a batch form, such that a cache can be “primed” with entries through a bulk load method, or that multiple objects can be stored, removed, and invalidated with a single method to cut down on per-store operation overhead.
Loaders can inherit from two interfaces that support methods for supporting the store and remove methods on the loader:
| • | The preload methods are exposed in the BulkCacheLoader interface. |
| • | The store, remove, and clear methods are exposed in another interface, CacheStore, and can be used by the underlying cache mechanism for modifying the content of cache puts and removals on the backend datastore. The cache mechanism can then invalidate the corresponding entry or entries for all other caches listening on that region, if applicable. |
It is possible that the backend store gets updated without sending an invalidation message to all other clients. If this scenario is detected, it throws an exception indicating a loss of synchronization, but the cache client must handle recovery from that point on.
The caching system in GridServer does not provide a mechanism to auto-update data in the cache when it changes in the backend, if done so by a mechanism other than those offered by the CacheStore interface.
Support is available for datastore write-through, bulk write-through, remove, bulk remove and bulk load, on both global and local loaders, in Java and .NET.