Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] J2SE Caching Strategy?

Ok, I need some help demystifying caching for a J2SE app.

We're at the stage in our application where it's time to optimize
caching. Things are not acting quite like I thought they would, and
the docs are currently Server Container based.

Here's the ideal situation:
---
  - Inside one EM (session) caching is fine.
  - When a new EM starts, it's entities should always read from the
database unless overriden with a @Cache annotation
  - On an Entity by Entity Basis we would like to turn on caching
full/soft. This would be for data that is not volatile -- drop down
values, etc.


Here's how we (tried) to implement.

We set the CACHE_TYPE_DEFAULT to SoftWeak in the EMF's properties.

On an entity by entity basis with the @Cache annotation we set a
SoftWeak CacheType but turned alwaysRefresh to true.

Always Refresh seemed to be ignored, even though it was set to be true
in the annotation. (Maybe because we were doing a Find by ID?) Is
there maybe a way it can be set on the EMF level? I couldn't find a
property for it, just on the annotation.
    -  As a work-around we tried to set the expiry to 1ms. That was
not fun! It got caught in an infinite loop refreshing & refreshing as
I assume everything expired before the whole Entity and it's
relationships could be loaded. An expiry of 1000 ms worked fine,  but
makes me worry if an entity does not finishing loading in less than
the cache expiry you could be caught in another infinite loop -- not
to mention that whole thing seems a bit hacky for implementing no
cache.

Next we tried setting the CacheType to NONE in the @Cache annotation
this had no effect, and I believe at EclipseCon Doug said that NONE
doesn't do what you'd think it would.


Also while we're talking cache -- is there a way to invalidate the
entire cache programatically?

I saw on Wonseok's blog that he reccommended doing things like calling
refresh on the EM after find calls and query hints on all your
queries, but it seems to me that's a bit too mcuh boilerplate & my use
case should be able to be accomplished with a sane default policy +
selective overriding.

I think my cache use case will be a very common one for database
driven RCP business apps, so this will probably be asked a few times
in the future.


Thanks as always!
Tim


Back to the top