Find - returns detached or cached? [message #801744] |
Sat, 18 February 2012 22:11 |
Marvin Toll Messages: 34 Registered: July 2009 |
Member |
|
|
A query can be programmed to returned a cached instance of an entity:
// This hint ensure that the shared instance be returned from cache.
query.setHint(QueryHints.READ_ONLY, HintValues.TRUE);
Is there the same control for a "find()"?
Does a find (by default) return a detached instance or reference to shared cache if an entity is cacheable?
Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
[Updated on: Sat, 18 February 2012 22:13] Report message to a moderator
|
|
|
|
|
|
|
|
Re: Find - returns detached or cached? [message #809651 is a reply to message #808388] |
Wed, 29 February 2012 04:45 |
Marvin Toll Messages: 34 Registered: July 2009 |
Member |
|
|
Let's go back to the starting point. If a read-only query is executed are the results in both L1 and L2 cache? That is, are the instances considered "cached" - meaning both L2 and L1?
We have ~6 GB of data we want in L2 cache only (in the form of a List<DebtorQO>)... so that it can be shared by multiple requests. How do we accomplish this? We do not have sufficient memory for every request (that executes the query - and refreshes L2 cache) to have it's own L1 set of instances.
/**
* This class is a Query Object for performance optimization.
*/
@Entity
@ReadOnly
@Cacheable(true)
@Cache(size = 60000000, alwaysRefresh = true, refreshOnlyIfNewer = true)
@Table(name = "DEBTOR")
public class DebtorQO extends TopBaseUuidNoAuditBO {
private static final long serialVersionUID = 1L;
@Column(name = "DEBTOR_TIN_NR")
private int debtorTin;
@Column(name = "UUID_KEY")
@Id
private byte[] debtorUuid;
/**
* Constructor
*/
public DebtorQO() {
super();
return;
}
/**
* Constructor
*
* @param debtorUuid
* @param debtorTin
* @param updateTime
*
*/
public DebtorQO(final byte[] debtorUuid, final int debtorTin,
final Timestamp updateTime) {
this.debtorUuid = debtorUuid;
this.debtorTin = debtorTin;
this.updateTime = updateTime;
return;
}
... Accessor methods here...
And the query:
<named-query name="QueryDebtorTinByStatus">
<query>
SELECT new gov.treas.fms.top.domain.entity.debt.DebtorQO(debtor.uuid, debtor.debtorTin, debtor.updateTime)
FROM DebtorBO debtor
WHERE debtor.debtorStatus = :debtorStatus
</query>
</named-query>
Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
[Updated on: Wed, 29 February 2012 13:06] Report message to a moderator
|
|
|
|
Re: Find - returns detached or cached? [message #815007 is a reply to message #810808] |
Wed, 07 March 2012 05:31 |
Marvin Toll Messages: 34 Registered: July 2009 |
Member |
|
|
As follow-up... here is the API we are implementing in SOAj to clarify the state of L1 and L2 cache:
• containsInstanceInPersistenceContext()
• containsInstanceInSharedCache()
• clearAllInstancesFromPersistenceContext()
• detachInstanceFromPersistenceContext()
• evictSingleInstanceFromSharedCache()
• evictInstancesFromSharedCache()
• evictAllInstancesFromSharedCache()
Marvin Toll
CTO, Pattern Enabled Development
http://pedCentral.com
|
|
|
Powered by
FUDForum. Page generated in 0.04111 seconds