1.2. Per-Invocation Flags
1.2. Per-Invocation Flags Per-invocation flags can be used with data grids in Red Hat JBoss Data Grid to specify behavior for each cache call. Per-invocation flags facilitate the implementation of potentially time saving optimizations. Report a bug 1.2.1. Per-Invocation Flag Functions The putForExternalRead() method in Red Hat JBoss Data Grid's Cache API uses flags internally. This method can load a JBoss Data Grid cache with data loaded from an external resource. To improve the efficiency of this call, JBoss Data Grid calls a normal put operation passing the following flags: The ZERO_LOCK_ACQUISITION_TIMEOUT flag: JBoss Data Grid uses an almost zero lock acquisition time when loading data from an external source into a cache. The FAIL_SILENTLY flag: If the locks cannot be acquired, JBoss Data Grid fails silently without throwing any lock acquisition exceptions. The FORCE_ASYNCHRONOUS flag: If clustered, the cache replicates asynchronously, irrespective of the cache mode set. As a result, a response from other nodes is not required. Combining the flags above significantly increases the efficiency of the operation. The basis for this efficiency is that putForExternalRead calls of this type are used because the client can retrieve the required data from a persistent store if the data cannot be found in memory. If the client encounters a cache miss, it retries the operation. For a detailed list of all flags available for JBoss Data Grid are available in the JBoss Data Grid API Documentation here: https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Data_Grid/6.6/html/API_Documentation/files/api/org/infinispan/context/Flag.html Report a bug 1.2.2. Configure Per-Invocation Flags To use per-invocation flags in Red Hat JBoss Data Grid, add the required flags to the advanced cache via the withFlags() method call. Example 1.1. Configuring Per-Invocation Flags Note The called flags only remain active for the duration of the cache operation. To use the same flags in multiple invocations within the same transaction, use the withFlags() method for each invocation. If the cache operation must be replicated onto another node, the flags are also carried over to the remote nodes. Report a bug 1.2.3. Per-Invocation Flags Example In a use case for Red Hat JBoss Data Grid, where a write operation, such as put() , must not return the value, the IGNORE_RETURN_VALUES flag is used. This flag prevents a remote lookup (to get the value) in a distributed environment, which in turn prevents the retrieval of the undesired, potential, value. Additionally, if the cache is configured with a cache loader, this flag prevents the value from being loaded from its cache store. Example 1.2. Using the IGNORE_RETURN_VALUES Flag Report a bug
Cache cache = cache.getAdvancedCache() .withFlags(Flag.SKIP_CACHE_STORE, Flag.CACHE_MODE_LOCAL) .put("local", "only"); Cache cache = cache.getAdvancedCache() .withFlags(Flag.IGNORE_RETURN_VALUES) .put("local", "only")