[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Full Identity Map that has relationships to objects cached in weaker types
|
I'm assuming your requirement is that you want all users to stay cached (i.e. you're not upper-limiting the user cache so that at any time it only has some small subset - in which case this is a non-issue anyway).
I would really tend to view this as a domain-specific issue that is better dealt with at the application level (vs. somehow handled 'correctly' by the framework). For example, does User really need to a reference to Message anyway? In your context 'User' smells a lot like a referential piece of data and Message is transactional. So you could instead simply have a Message broker service which given the User, retrieves the relevant messages when you need them using a read all query. Or if you really wanted User to retain the (lazy) message collection in User, you could access it and then immediately after refresh the user object back to a state where the collection is uninitialized (but this approach is semantically equivalent to the broker anyway, just a bit clumsier and makes the intent unclear).
If you really, really wanted to keep the current domain model exactly intact, I think the only way to accomplish that would be to:
(a) use a collection composed of weak references. Eclipselink doesn't currently support this, but it seems like it would be possible by implementing a new container policy, etc - but it would probably be tricky and in this case you're deep in the realm of extending Eclipselink itself.
(b) make an entirely new kind of cache that does not store the object itself, but just some "frozen" representation (i.e. would only have direct field values, no reference). This is essentiallly what the Hibernate second level cache does. (On the down side, this makes the secondary cache a fair bit slower, since it needs to 'unthaw' the object)
That all said, I've only been using Ecliselink for a short while myself, so I'd be interested to hear if there is some other trick Eclipselink has up it's sleeve for this kind of case...
On Sun, Dec 28, 2008 at 9:25 AM, zebhed
<zebhed@xxxxxxx> wrote:
Thanks Jason, thanks Gordon.
Ok, this could be a problem. I want to make an example:
I have an entity User that has a one-to-many relationship to Message (User
(1) -> Message (N)). I have to cache all Users, but I do not want to cache
all Messages.
Let´s say I have 100.000 users and every user has about 100 messages. As I
said, I want to cache all Users but only a few messages (let´s say about
10.000). Now I can think of two approaches.
a) I cache all Users by using a Full Identity Map. Messages are cached by
using a Weak Identity Map. The problem is that Messages will never be
garbage collected (unless they are deleted), because they are hard
referenced by the User. This will lead to extreme memory consumption (and
Out-Of-Memory-Errors).
b) I cache all Users by using a Soft Cache Weak Identity Map. Messages are
cached by using a Weak Identity Map. I doubt a Soft Cache Weak Identity Map
is still performant when its size is very large (100.000). This is because
it is implemented as a LinkedList and every look up of an entity will cost
O(n). This leads to another very important question. What should be the
maximum size of a Soft Cache Weak Identity Map so that it still performs
well?
I wonder what would be the best solution in this case.
--
View this message in context: http://www.nabble.com/Full-Identity-Map-that-has-relationships-to-objects-cached-in-weaker-types-tp21188540p21193184.html