Click on Javadoc link to open Javadoc documentation.
Package
org.gridgain.grid.cache ![]()
Description
This interface defines grid cache configuration. This configuration is passed to grid via GridConfiguration.getCacheConfiguration() ![]()
Note, that absolutely every configuration property in GridCacheConfiguration ![]()
![]()
![]()
The following configuration parameters can be used to configure cache with GridCacheConfigurationAdapter ![]()
| Setter Method | Description | Optional | Default |
|---|---|---|---|
| setName(String) |
Cache name. | Yes | null |
| setCacheMode(GridCacheMode) |
Caching mode to use. You can configure cache either to be local-only, fully replicated, partitioned, or near. | Yes | GridCacheMode.REPLICATED |
| setAffinity(GridCacheAffinity) |
Key topology resolver to provide mapping from keys to nodes. | Yes | null |
| setAffinityMapper(GridCacheAffinityMapper) |
Affinity key mapper used to provide custom affinity key for any given key. | Yes | GridCacheDefaultAffinityMapper |
| setAtomicSequenceReserveSize(int) | Default number of sequence values reserved for GridCacheAtomicSequence instances. | Yes | 1000 |
| setAutoIndexQueryTypes(Collection<GridCacheQueryType>) |
Query types to use to auto index values of boxed and unboxed primitive types, Strings and Dates. | Yes | null |
| setBatchUpdateOnCommit(boolean) |
If true, then all transactional values will be written to persistent storage at commit phase. If false, then values will be persisted after every operation. | Yes | true |
| setCloner(GridCacheCloner) |
Cloner to be used for cloning values that are returned to user only if GridCacheFlag.CLONE |
Yes | GridCacheBasicCloner |
| setDefaultLockTimeout(long) |
Default lock timeout. | Yes | 0, which means that lock acquisition will never timeout |
| setDefaultTimeToLive(long) |
Time to live for all objects in cache. | Yes | 0, which means that objects never expire |
| setDefaultTxConcurrency(GridCacheTxConcurrency) |
Default cache transaction concurrency. | Yes | GridCacheTxConcurrency.OPTIMISTIC |
| setDefaultTxIsolation(GridCacheTxIsolation) |
Default cache transaction isolation. | Yes | GridCacheTxIsolation.REPEATABLE_READ |
| setDefaultTxTimeout(long) |
Default transaction timeout. | Yes | 0, which means that transactions will never timeout |
| setEvictionPolicy(GridCacheEvictionPolicy) |
Cache eviction policy. | Yes | GridCacheLirsEvictionPolicy |
| setGarbageCollectorFrequency(int) |
Frequency at which distributed garbage collector will check other nodes if there are any zombie locks left over. | Yes | 0, which means that GC is disabled |
| setIndexAnalyzeFrequency(long) |
Frequency of running H2 "ANALYZE" command in order to update selectivity statistics of H2 database tables. | Yes | 10 minutes |
| setIndexAnalyzeSampleSize(long) |
Number of samples used to run H2 "ANALYZE" command in order to update selectivity statistics of H2 database tables. | Yes | 10000 |
| setIndexCleanup(boolean) |
Flag indicating whether query storage should be deleted or not upon start. | Yes | true |
| setIndexFixedTyping(boolean) |
Flag indicating that the same key object can only be associated with the same value type and a value type can only be associated with keys of the same type. | Yes | true |
| setIndexFullClassName(boolean) |
Flag indicating whether full class names or simple class namess should be used in queries. | Yes | false |
| setIndexH2Options(String) |
Addition options to H2 database (query storage). | Yes | null |
| setIndexMemoryOnly(boolean) |
Flag indicating whether query index should be stored only in memory (not on disk). | Yes | false |
| setIndexMaxOperationMemory(int) |
Maximum memory used per single operation with query index (store and remove), in bytes. | Yes | 100000 |
| setIndexPassword(String) |
Optional password for index store. | Yes | null |
| setIndexPath(String) |
Absolute or relative to GRIDGAIN_HOME path for storing query indexes on disk. | Yes | GRIDGAIN_HOME/work/cache/indexes |
| setIndexUsername(String) |
Optional user name for index store. | Yes | null |
| setInvalidate(boolean) |
Invalidation flag. | Yes | false |
| setNearEnabled(boolean) |
Indicates whether near cache is enabled in case of GridCacheMode.PARTITIONED |
Yes | true |
| setNearEvictionPolicy(GridCacheEvictionPolicy) |
Eviction policy for near cache. | Yes | GridCacheLirsEvictionPolicy |
| setNearStartSize(int) |
Initial cache size for near cache. | Yes | 1024 |
| setPreloadBatchSize(int) |
Size (in number bytes) to be loaded within a single preload message. | Yes | 102400 |
| setPreloadMode(GridCachePreloadMode) |
Preload mode for distributed cache. | Yes | GridCachePreloadMode.ASYNC |
| setPreloadThreadPoolSize(int) | Size of preloading thread pool. | Yes | 2 |
| setRefreshAheadRatio(double) |
Refresh-ahead ratio. | Yes | 0 |
| setStartSize(int) |
Initial cache size. | Yes | 1024 |
| setStore(GridCacheStore) |
Persistent storage for read-through and write-through operations. | Yes | null |
| setStoreEnabled(boolean) |
Flag indicating whether GridGain should activate read-through/write-through behaviour by default. | Yes | true |
| setSwapEnabled(boolean) |
Flag indicating whether GridGain should use swap storage by default if user did not specify this explicitly using those methods whether it is possible. | Yes | true |
| setSynchronousCommit(boolean) |
Flag indicating whether GridGain should wait for commit replies from all nodes. | Yes | false |
| setSynchronousRollback(boolean) |
Flag indicating whether GridGain should wait for rollback replies from all nodes. | Yes | false |
| setTransactionManagerLookup(GridCacheTmLookup) |
Transaction manager finder for integration for JEE app servers. | Yes | null |
Some of the most commonly used configuration properties are explained in more detail below.
Name
Name of the cache. If not provided or null, then this will be considered a default cache. It can be accessed via Grid.cache() ![]()
![]()
Cache Mode
Caching mode to use. You can configure cache either to be local-only, fully replicated, partitioned, or near. If not provided, REPLICATED ![]()
In LOCAL ![]()
In REPLICATED ![]()
![]()
In PARTITIONED mode the overall key set will be divided into partitions and all partitions will be split equally between participating nodes. User has affinity control over key assignment via GridCacheAffinity ![]()
![]()
![]()
Affinity
Cache key affinity which maps keys to nodes (utilized for replicated and partitioned caches). Whenever a key is given to cache, it is first passed to a pluggable GridCacheAffinityMapper ![]()
![]()
![]()
![]()
![]()
![]()
Examples
GridCacheConfiguration ![]()
GridConfigurationAdapter c = new GridConfigurationAdapter(); GridCacheConfigurationAdapter cc = new GridCacheConfigurationAdapter(); cc.setName("replicated"); cc.setCacheMode(GridCacheMode.PARTITIONED); cc.setSynchronousCommit(true); cc.setStartSize(20); cc.setAffinity(new GridCachePartitionedAffinity<Object>(0, 10)); c.setCacheConfiguration(cc); G.start(c);
or from Spring configuration file:
<!-- Local cache with custom initial size. --> <bean class="org.gridgain.grid.cache.GridCacheConfigurationAdapter"> <!-- Cache name is 'local'. --> <property name="name" value="local"/> <!-- LOCAL cache mode. --> <property name="cacheMode" value="LOCAL"/> <!-- Initial cache size. --> <property name="startSize" value="20"/> </bean>
<!-- Replicated cache with synchronous preloading and synchronous commit. --> <bean class="org.gridgain.grid.cache.GridCacheConfigurationAdapter"> <!-- Cache name is 'replicated'. --> <property name="name" value="replicated"/> <!-- REPLICATED cache mode. --> <property name="cacheMode" value="REPLICATED"/> <!-- Set synchronous preloading (default is asynchronous). --> <property name="preloadMode" value="SYNC"/> <!-- Set synchronous commit to true. --> <property name="synchronousCommit" value="true"/> </bean>
<!-- Partitioned cache with LRU eviction policy and custom number of backups. --> <bean class="org.gridgain.grid.cache.GridCacheConfigurationAdapter"> <!-- Cache name is 'partitioned'. --> <property name="name" value="partitioned"/> <!-- PARTITIONED cache mode. --> <property name="cacheMode" value="PARTITIONED"/> <!-- Optional eviction policy (GridCacheLirsEvictionPolicy is used by default). --> <property name="evictionPolicy"> <bean class="org.gridgain.grid.cache.eviction.lru.GridCacheLruEvictionPolicy"> <property name="maxSize" value="100"/> </bean> </property> <!-- Set the number of backups to 0 (default is 1). --> <property name="affinity"> <bean class="org.gridgain.grid.cache.affinity.partitioned.GridCachePartitionedAffinity"> <constructor-arg value="0"/> <constructor-arg value="10"/> </bean> </property> </bean>

For more information about using Spring framework for configuration click here.
