此内容没有您所选择的语言版本。

Chapter 18. Cache Writing Modes


Red Hat JBoss Data Grid presents configuration options with a single or multiple cache stores. This allows it to store data in a persistent location, for example a shared JDBC database or a local file system. JBoss Data Grid supports two caching modes:
  • Write-Through (Synchronous)
  • Write-Behind (Asynchronous)

18.1. Write-Through Caching

The Write-Through (or Synchronous) mode in Red Hat JBoss Data Grid ensures that when clients update a cache entry (usually via a Cache.put() invocation), the call does not return until JBoss Data Grid has located and updated the underlying cache store. This feature allows updates to the cache store to be concluded within the client thread boundaries.

18.1.1. Write-Through Caching Benefits

The primary advantage of the Write-Through mode is that the cache and cache store are updated simultaneously, which ensures that the cache store remains consistent with the cache contents. This is at the cost of reduced performance for cache operations caused by the cache store accesses and updates during cache operations.

18.1.2. Write-Through Caching Configuration (Library Mode)

No specific configuration operations are required to configure a Write-Through or synchronous cache store. All cache stores are Write-Through or synchronous unless explicitly marked as Write-Behind or asynchronous. The following procedure demonstrates a sample configuration file of a Write-Through unshared local file cache store.

Procedure 18.1. Configure a Write-Through Local File Cache Store

  1. Identify the namedCache

    The name parameter specifies the name of the namedCache to use.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    
    Copy to Clipboard Toggle word wrap
  2. Configure the Cache Loader

    The shared parameter is used when multiple cache instances share a cache store. This parameter can be set to prevent multiple cache instances writing the same modification multiple times. Valid values for this parameter are true and false.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    
    Copy to Clipboard Toggle word wrap
  3. Specify the Loader Class

    The class attribute defines the class of the cache loader implementation.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    		<store class="org.infinispan.loaders.file.FileCacheStore"
    
    Copy to Clipboard Toggle word wrap
  4. Configure the fetchPersistentState Parameter

    The fetchPersistentState parameter determines whether the persistent state is fetched when joining a cluster. Set this to true if using a replication and invalidation in a clustered environment. Additionally, if multiple cache stores are chained, only one cache store can have this property enabled. If a shared cache store is used, the cache does not allow a persistent state transfer despite this property being set to true. The fetchPersistentState parameter is false by default.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    		<store class="org.infinispan.loaders.file.FileCacheStore" 
    	       			fetchPersistentState="true"
    
    Copy to Clipboard Toggle word wrap
  5. Set the ignoreModifications Parameter

    The ignoreModifications parameter determines whether operations that modify the cache (e.g. put, remove, clear, store, etc.) do not affect the cache store. As a result, the cache store can become out of sync with the cache.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    		<store class="org.infinispan.loaders.file.FileCacheStore" 
    	       			fetchPersistentState="true" 
    	       			ignoreModifications="false"
    
    Copy to Clipboard Toggle word wrap
  6. Configure Purge On Startup

    The purgeOnStartup parameter specifies whether the cache is purged when initially started.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    		<store class="org.infinispan.loaders.file.FileCacheStore" 
    	       			fetchPersistentState="true" 
    	       			ignoreModifications="false"
    	       			purgeOnStartup="false">
    
    Copy to Clipboard Toggle word wrap
  7. The property Element

    The property element contains information about properties related to the cache store.
    1. The name parameter specifies the name of the property.
    <?xml version="1.0" encoding="UTF-8"?>
    <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns="urn:infinispan:config:5.0">
    	<global />
    	<default />
    	<namedCache name="persistentCache">
    		<persistence shared="false">
    		<store class="org.infinispan.loaders.file.FileCacheStore" 
    	       			fetchPersistentState="true" 
    	       			ignoreModifications="false"
    	       			purgeOnStartup="false">
    				<properties>
    					<property name="location" 
    						  value="${java.io.tmpdir}" />
    				</properties>
    			</store>
    		</persistence>
      	</namedCache>
    </infinispan>
    
    
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat