About Blocking and Self-Populating Caches

The net.sf.ehcache.constructs package contains some applied caching classes which use the core classes to solve everyday caching problems. Two of these are BlockingCache and SelfPopulatingCache.

Blocking Cache

Imagine you have a very busy web site with thousands of concurrent users. Rather than being evenly distributed in what they do, they tend to gravitate to popular pages. These pages are not static, they have dynamic data which goes stale in a few minutes. Or imagine you have collections of data which go stale in a few minutes. In each case the data is extremely expensive to calculate. If each request thread asks for the same thing, that is a lot of work. Now, add a cache. Get each thread to check the cache; if the data is not there, go and get it and put it in the cache.

Now, imagine that there are so many users contending for the same data that in the time it takes the first user to request the data and put it in the cache, ten other users have done the same thing. The upstream system, whether a JSP or velocity page, or interactions with a service layer or database are doing ten times more work than they need to. Enter the BlockingCache. It is blocking because all threads requesting the same key wait for the first thread to complete. Once the first thread has completed the other threads simply obtain the cache entry and return. The BlockingCache can scale up to very busy systems. Each thread can either wait indefinitely, or you can specify a timeout using the timeoutMillis constructor argument.

For more information, see the Javadoc for BlockingCache.

SelfPopulatingCache

Sometimes, you want to use the BlockingCache, but the requirement to always release the lock results in complicated code. You also want to think about what you are doing without thinking about the caching. Enter the SelfPopulatingCache.

SelfPopulatingCache is synonymous with pull-through cache, which is a common caching term. However, SelfPopulatingCache is always used in addition to a BlockingCache.

SelfPopulatingCache uses a CacheEntryFactory which, given a key, knows how to populate the entry.

Note: JCache inspired getWithLoader and getAllWithLoader directly in Ehcache, which work with a CacheLoader may be used as an alternative to SelfPopulatingCache.

For more information, see the Javadoc for SelfPopulatingCache.

Ehcache(2.9.x) - API Developer Guide, Blocking and Self Populating Caches的更多相关文章

  1. Ehcache(2.9.x) - API Developer Guide, Cache Extensions

    About Cache Extensions Cache extensions are a general-purpose mechanism to allow generic extensions ...

  2. Ehcache(2.9.x) - API Developer Guide, Key Classes and Methods

    About the Key Classes Ehcache consists of a CacheManager, which manages logical data sets represente ...

  3. Ehcache(2.9.x) - API Developer Guide, Write-Through and Write-Behind Caches

    About Write-Through and Write-Behind Caches Write-through caching is a caching pattern where writes ...

  4. Ehcache(2.9.x) - API Developer Guide, Cache Eviction Algorithms

    About Cache Eviction Algorithms A cache eviction algorithm is a way of deciding which element to evi ...

  5. Ehcache(2.9.x) - API Developer Guide, Basic Caching

    Creating a CacheManager All usages of the Ehcache API start with the creation of a CacheManager. The ...

  6. Ehcache(2.9.x) - API Developer Guide, Cache Usage Patterns

    There are several common access patterns when using a cache. Ehcache supports the following patterns ...

  7. Ehcache(2.9.x) - API Developer Guide, Searching a Cache

    About Searching The Search API allows you to execute arbitrarily complex queries against caches. The ...

  8. Ehcache(2.9.x) - API Developer Guide, Using Explicit Locking

    About Explicit Locking Ehcache contains an implementation which provides for explicit locking, using ...

  9. Ehcache(2.9.x) - API Developer Guide, Transaction Support

    About Transaction Support Transactions are supported in versions of Ehcache 2.0 and higher. The 2.3. ...

随机推荐

  1. 【多校练习4签到题】HDU 4642—— Fliping game

    来源:点击打开链接 看上去很难,比赛的时候光看hehe了,也没有想. 但是仔细想想,是可以想出来的.一个棋盘上每个格子摆放一个硬币,硬币有正面1和反面0之分.现在两个人可以按照规则翻硬币,选择(x,y ...

  2. 超级终端和SecureCRT进行Console口的连接

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html 内部邀请码:C8E245J (不写邀请码,没有现金送) 国 ...

  3. Wps的ppt里 让图片按顺序出现 就是点击一下 出现一张照片

    基本操作能够用两种方法来实现: 方法一.每页幻灯片插入一张图片,幻灯片默认就是单击鼠标切换幻灯片的,所以不用再做其它设置. 方法二.在一页幻灯片中插入多张图片,全选图片(插入图片后,点击图片,Ctrl ...

  4. Java网页数据采集器[上篇-数据采集]【转载】

    开篇 作为全球运用最广泛的语言,Java 凭借它的高效性,可移植性(跨平台),代码的健壮性以及强大的可扩展性,深受广大应用程序开发者的喜爱. 作为一门强大的开发语言,正则表达式在其中的应用当然是必不可 ...

  5. Plus One @LeetCode

    import java.util.Arrays; /** * Plus One * * Given a number represented as an array of digits, plus o ...

  6. Zend Studio / Ecliplse插件StartExplorer

    Install site.zip (quick and simple way) Locate zip file under site\target in Project Explorer, Start ...

  7. 在Linux里设置环境变量的方法(export PATH)

    一般来说,配置交叉编译工具链的时候需要指定编译工具的路径,此时就需要设置环境变量.例如我的mips-linux-gcc编译器在“/opt/au1200_rm/build_tools/bin”目录下,b ...

  8. IntellijIdea中常用的快捷键

    快速查找类:Ctrl+N 提示:Ctrl+Space 提示:Ctrl+Shift+Space 查看documentation:Ctrl+Q 查找类.方法.变量的引用:Alt+F7 定位类.方法.变量的 ...

  9. graylog2 架构--转载

    原文地址:http://docs.graylog.org/en/latest/pages/architecture.html Architectural considerations There ar ...

  10. C - Minimum Inversion Number

    Description The inversion number of a given number sequence a1, a2, ..., an is the number of pairs ( ...