Skip to main content

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

Hi Tim,

   Can you clarify your issues/goals before we get into how best to solve them?

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
  
It's important to distinguish between the shared "L2" cache (in the EntityManagerFactory) and the transaction level "L1" cache.  The only thing in the L2 cache are objects read from the database or objects created or modified by an EM transaction (having been read originally through the EMF) that has successfully committed to the database.  In other words, changes in an EM that have not been committed are not visible in the L2 cache.

So you don't want the EM-2 to see changes committed by EM-1?  Reading from the database will just get you the same answer as you'll get from the L2
cache unless you have third parties modifying the database behind the scenes.  Is this the root problem you're trying to combat?

    Shaun


  - 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
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  

--


Oracle
Shaun Smith | Principal Product Manager, TopLink | +1.905.502.3094
Oracle Fusion Middleware
110 Matheson Boulevard West, Suite 100
Mississauga, Ontario, Canada L5R 3P4

Back to the top