Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write behind cache Ehcache new feature?

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?

like image 557
cometta Avatar asked May 12 '10 09:05

cometta


2 Answers

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 :)

like image 147
Pascal Thivent Avatar answered Nov 10 '22 21:11

Pascal Thivent


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.

like image 32
skaffman Avatar answered Nov 10 '22 21:11

skaffman