このコンテンツは選択した言語では利用できません。

Chapter 4. Cache Loaders


Q: What is a cache loader?
Q: Is the FileCacheLoader recommended for production use?
Q: Can writing to cache loaders be asynchronous?
Q: Can I write my own cache loader?
Q: Does a cache loader have to use a persistent store?
Q: Can I use more than one cache loader?
Q: Can I migrate a JDBCacheLoader or FileCacheLoader based cache store containing data formatted with JBoss Cache 1.x.x to JBoss Cache 2.0 format?
Q: Is the TCPDelegatingCacheLoader resilient to TCPCacheServer restarts?
Q:
What is a cache loader?
A:
A cache loader is the connection of JBoss Cache to a (persistent) data store. The cache loader is called by JBoss Cache to fetch data from a store when that data is not in the cache, and when modifications are made to data in the cache the Cache Loader is called to store those modifications back to the store.
In conjunction with eviction policies, JBoss Cache with a cache loader allows a user to maintain a bounded cache for a large backend datastore. Frequently used data is fetched from the datastore into the cache, and the least used data is evicted, in order to provide fast access to frequently accessed data. This is all configured through XML, and the programmer doesn't have to take care of loading and eviction.
JBoss Cache currently ships with several cache loader implementations, including:
  • org.jboss.cache.loader.FileCacheLoader: this implementation uses the file system to store and retrieve data. JBoss Cache nodes are mapped to directories, subnodes to subdirectories, etc. Attributes of a node are mapped to a data file inside the directory.
  • org.jboss.cache.loader.jdbm.JdbmCacheLoader: this implementation is based on JDBM, an open source file-based transactional persistence engine.
  • org.jboss.cache.loader.bdbje.BdbjeCacheLoader: this implementation is based on Oracle's Berkeley DB Java Edition database, a fast and efficient transactional database. It uses a single file for the entire store. Note that if you use the Berkeley DB cache loader with JBoss Cache and wish to ship your product, you will have to acquire a commercial license from Oracle.
  • org.jboss.cache.loader.JDBCCacheLoader: this implementation uses the relational database as the persistent storage.
  • And more. See the chapter on cache loaders in the JBoss Cache User Guide for more details.
Q:
Is the FileCacheLoader recommended for production use?
A:
No, it is not. The FileCacheLoader has some severe limitations which restrict its use in a production environment, or if used in such an environment, it should be used with due care and sufficient understanding of these limitations.
  • Due to the way the FileCacheLoader represents a tree structure on disk (directories and files) traversal is inefficient for deep trees.
  • Usage on shared filesystems like NFS, Windows shares, etc. should be avoided as these do not implement proper file locking and can cause data corruption.
  • Usage with an isolation level of NONE can cause corrupt writes as multiple threads attempt to write to the same file.
  • File systems are inherently not transactional, so when attempting to use your cache in a transactional context, failures when writing to the file (which happens during the commit phase) cannot be recovered.
As a rule of thumb, it is recommended that the FileCacheLoader not be used in a highly concurrent, transactional or stressful environment, and its use is restricted to testing.
Q:
Can writing to cache loaders be asynchronous?
A:
Yes. Set the async attribute to true. See the JBoss Cache Users' Guide for a more detailed discussion. By default though, all cache loader writes are synchronous and will block.
Q:
Can I write my own cache loader?
A:
Yes. A cache loader is a class implementing org.jboss.cache.loader.CacheLoader or extending org.jboss.cache.loader.AbstractCacheLoader. It is configured via the XML file (see JBoss Cache User Guide).
Q:
Does a cache loader have to use a persistent store?
A:
No. A cache loader could, for example, fetch (and possibly store) its data from a webdav-capable webserver. Another example is a caching proxy server, which fetches contents from the web. Note that an implementation of CacheLoader may not implement the 'store' functionality in this case, but just the 'load' functionality.
Q:
Can I use more than one cache loader?
A:
Yes. Within the CacheLoaderConfiguration XML element (see the JBoss Cache User Guide chapter on cache loaders) you can describe several cache loaders. The impact is that the cache will look at all of the cache loaders in the order they've been configured, until it finds a valid, non-null element of data. When performing writes, all cache loaders are written to (except if the ignoreModifications element has been set to true for a specific cache loader).
Q:
Can I migrate a JDBCacheLoader or FileCacheLoader based cache store containing data formatted with JBoss Cache 1.x.x to JBoss Cache 2.0 format?
A:
Yes. See the "Transforming Cache Loaders" section within the "Cache Loaders" section located in the JBoss Cache User Guide.
Q:
Is the TCPDelegatingCacheLoader resilient to TCPCacheServer restarts?
A:
As of JBoss Cache 2.1.0, the answer is yes. See the JBoss Cache User Guide for details on how to configure and tune your retries and wait period for reestablishing the TCP connection.
Prior to that, restarting the TCPCacheServer would also mean restarting your application that uses the cache.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat