Home » Eclipse Projects » EclipseLink » EL cache invalidation capabilities does not work(EL cache invalidation capabilities does not work)
EL cache invalidation capabilities does not work [message #1485798] |
Mon, 24 November 2014 14:58 |
Taurine T Messages: 2 Registered: November 2014 |
Junior Member |
|
|
Hi,
I am dealing with a situation where ,overnight, a series of batch processes update database tables, leaving my Toplink cache with potentially hundreds of stale objects.
To solve this issue, I intend to use the invalidation (object invalidation, class invalidation, time invalidation ...etc) capabilities of cache invalidation but I note that this invalidation work only for execution of new query on invalidated objects.
Access to an invalidated object by graph object navigation return stale object !
I have write a small example with TopLink demonstration project (employee-project)
package examples.sessions.twotier.examples.cache;
import examples.sessions.twotier.Example;
import examples.sessions.twotier.model.Address;
import examples.sessions.twotier.model.Employee;
import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
public class PhoneCache extends Example {
Employee employee;
Address address;
public void run() {
log("\t find one employee ...: ");
findEmployee();
log("\t Résult of findEmployee() : " + employee);
log("\t 1st execution of address = employee.getAddress() ... ");
address = employee.getAddress();
log("\t Result of 1st execution of address = employee.getAddress() : " + address);
log("\t invalidate address ... : ");
getSession().getIdentityMapAccessor().invalidateObject(address);
log("\t execute address = employee.getAddress() ... ");
address = employee.getAddress();
log("\t result of address = employee.getAddress() : " +
address);
log("\t explicitly invalidate address by query findAddressById(address.getId()) ...: ");
findAddressById(address.getId());
log("\t result of explicit invalidation address by query findAddressById(address.getId()) : " +
address);
}
private void findEmployee() {
employee = (Employee)getSession().readObject(Employee.class);
}
private void findAddressById(long adrId) {
ExpressionBuilder builder = new ExpressionBuilder();
Expression exp = (builder.get("id").equal(adrId));
address = (Address)getSession().readObject(Address.class, exp);
}
public static void main(String[] args) {
new PhoneCache().runExample();
}
}
When i execute this example i get this result :
[TopLink - Précis] : 2006.05.01 06:56:54.248--DatabaseSessionImpl(841)--Connection(878)--Thread(Thread[main,5,main])--SELECT t0.EMP_ID, t1.EMP_ID, t0.GENDER, t1.SALARY, t0.F_NAME, t0.L_NAME, t0.MANAGER_ID, t0.ADDR_ID, t0.END_DATE, t0.START_DATE, t0.END_TIME, t0.START_TIME, t0.VERSION FROM EMPLOYEE t0, SALARY t1 WHERE (t1.EMP_ID = t0.EMP_ID)
Résult of findEmployee() : Employee: Jill Austin
1st execution of address = employee.getAddress() ...
[TopLink - Précis] : 2006.05.01 06:56:54.589--DatabaseSessionImpl(841)--Connection(878)--Thread(Thread[main,5,main])--SELECT ADDRESS_ID, P_CODE, COUNTRY, PROVINCE, CITY, STREET FROM ADDRESS WHERE (ADDRESS_ID = 8)
Result of 1st execution of address = employee.getAddress() : Address: 1111 Mooseland Rd., Calgary, AB, Canada
invalidate address ... :
execute address = employee.getAddress() ...
result of address = employee.getAddress() : Address: 1111 Mooseland Rd., Calgary, AB, Canada
explicitly invalidate address by query findAddressById(address.getId()) ...:
[TopLink - Précis] : 2006.05.01 06:56:54.599--DatabaseSessionImpl(841)--Connection(878)--Thread(Thread[main,5,main])--SELECT ADDRESS_ID, P_CODE, COUNTRY, PROVINCE, CITY, STREET FROM ADDRESS WHERE (ADDRESS_ID = 8)
result of explicit invalidation address by query findAddressById(address.getId()) : Address: 1111 Mooseland Rd., Calgary, AB, Canada
Navigation to invalidated object ( employee.getAddress() ) return invalidated Object.
Object is realy invalidated by explicit new query on it (findAddressById()). But in real application triggered relation (employee.getAddress()) remain in memory.
We have the same problem when using bulKupdate API : UpdateAllQuery.
We know that toplink can not detect invalidation of objects managed by java references. We therefore modify the implementation of our
classes as follows:
1- Adding new transcient (not persistant) attribute "isValid (true/false)" on
each implementation of model classes.
2- Modify inter-objects navigation methods (objectA.getObjectB() method).
-- Example : Employee to Address navigation
Class Address{
String road;
...
isValid boolean;
}
Class Employee{
String name;
Address address;
...
isValid boolean;
public Address getAddress(){
if (!this.address.isValid)
refresh(this.address);
return this.address
}
}
To do this implementation we need to collect invalidation events to
modify "isValid" attribute (set isValid=false when object is invalidated).
We need to know how to track invalidation coming from :
* TopLink invalidation in "Cache coordination"
** API : TimeToLiveCacheInvalidationPolicy and DailyCacheInvalidationPolicy
Best regards
|
|
|
Goto Forum:
Current Time: Tue Mar 19 01:58:43 GMT 2024
Powered by FUDForum. Page generated in 0.02712 seconds
|