views:

284

answers:

3

Hi, i looking for guide/document/tutorial on how to use this new feature write-behind-cache in ehcache? Is there any demo in spring+jpa+ehcache+hibernate?

just to clariyfing, write-behind-cache mean each time we persist entity, it will be written into cache rather than into database correct?

+2  A: 

http://www.infoq.com/news/2010/05/ehcache-2.0

Ehcache 2.0 introduces write-through and write-behind caching. Write-through caching pattern is used by the applications to write data to the cache which causes writes to an underlying resource (e.g. a database). The cache acts as a facade to the underlying resource. Write-behind caching pattern uses the same client API, but the write happens asynchronously. The write-behind caching feature, supported as part of the new Ehcache API, works with asynchronous batching of updates to the database.

skaffman
@skaffman, ya man, that is the article that I read before posted the question. no tutorial how to use with spring+jpa+hibernate ?
cometta
A: 

I can't help you, just thought I'd mention GigaSpaces.

Adriaan Koster
Hibernate second level cache is not write-behind caching, regardless of the L2 caching provider you use (coherence, ehcache, gigaspace, whatever).
Pascal Thivent
I mention GigaSpaces to a user asking about write-behind caching and y ou downvote? Why? Whyyyyyyyyyy!
Adriaan Koster
+3  A: 

The fact that Ehcache offers Write-Behind Caching does NOT mean that any piece of software using Ehcache, like Hibernate, can leverage it without modification. From Terracotta's Hibernate Integration (note that this is a non independent post i.e. pro caching):

Write-Behind Caching

When you think of cache you will arrive at these cache strategies : Read-Through Caching, Write-Through Caching, Write-Behind Caching. Hibernate Second Level cache is Read-Write-Through Cache where if cache miss occurs, entity is read from database and then handed over to cache for susequent access. But H2LC is not Write-Behind caching. With Terracotta's disk persistence and asynchronsous module it would be really efficient for certain use-cases to implement write-behind. Currently Hibernate just directly writes to database. Instead if its modified to write to second level cache and persistent async-database-queue, this would decrease latency and increase throughput dramatically.

In other words, write-behind caching is just not how Hibernate currently works (and I may be wrong but I don't think this is going to change in a a near future). But feel free to raise a Jira issue :)

Pascal Thivent