[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
Mutable value objects - single user use of ehcache  XML
Forum Index -> Ehcache
Author Message
connors

neo

Joined: 08/17/2012 06:48:44
Messages: 4
Offline


Hi,

What is the expected behaviour for ehcache with mutable value objects, where the cache is persisted to disk?
There is no clustering here, just a simple single JVM using ehcache.

Our code does something like this:
1. create a cache
2. create a mutable serializable object - call it Value
3. put it into the cache under a particular key
4. wait for a few seconds
5. update the data within Value using setter methods

We only do the "put" once.
Should the Value written to disk be that from step 3 or step 5?

Under an older ehcache release (1.6.0-beta2), the write to disk was delayed until CacheManager.shutdown time.
Under the newer ehcache release (2.5.1), the write to disk is done almost immediately.

I have demo code and stack traces of the write points if you need them.
I can fix our application by doing a "re-put" when the mutable object changes.

What's the expected behaviour of ehcache here?

Thanks in advance,

Connor Sadler
ericm

jedi

Joined: 01/27/2011 17:23:34
Messages: 117
Offline

I believe in the older versions of Ehcache, you had to call cache.flush() or the shutdown to send the data to disk.

The newer versions do it automatically.

Take a look at Ehcache 2.6.0. It comes with a new restartable store. It is faster than the older versions and if your server crashes, the data will still be on disk.

I hope this helps.

Eric Mizell (Terracotta Engineer)
connors

neo

Joined: 08/17/2012 06:48:44
Messages: 4
Offline


Thanks for the reply.
Given that information, I'm gathering it's best not to cache an object then mutate it?
It sounds like this won't work with newer versions of ehcache.

klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 466
Offline

Users mutate cached objects all the time. Thats the purpose its for. Not sure I understand your scenario here.

Karthik Lalithraj (Terracotta)
connors

neo

Joined: 08/17/2012 06:48:44
Messages: 4
Offline


How do you mean they "mutate them all the time" ?
Do people generally change data inside value object instances after a put?
Or do you mean they put a brand new object under the same key?

The whole scenario is above, I don't know how to explain it further.
I can provide some code if that would help.

I think I may already have the answer to my question, though - ehcache will write to disk ASAP now so later object mutations will be lost.

Regards,

Connor
ericm

jedi

Joined: 01/27/2011 17:23:34
Messages: 117
Offline

I think what you mean is that Ehcache will write objects to disk as they are put or replaced. So disk will always have the most recent objects.

Is that the behavior you are looking for?


Eric Mizell (Terracotta Engineer)
connors

neo

Joined: 08/17/2012 06:48:44
Messages: 4
Offline


I am not looking for any behaviour.
I am asking, whats the expected behaviour?

I think the answer is given by what the current version of Ehcache does, so I'll leave it there.

Thanks for your input.

Regards,

Connor
 
Forum Index -> Ehcache
Go to:   
Powered by JForum 2.1.7 © JForum Team