clearCache: Entity based View Object and transient View Object Scenario

clearCache: Entity based View Object and transient View Object Scenario



Most of us feel that clearCache() on a viewObject is just a low key affair involving the flushing  out of VO rows from the cache but when you actually dig into the intricacies involved then you will find that there are quite a few operations involved under the covers.
here is the account of that -

Entity Object Based View Object Scenario:

For entity object based view object when we do a clearCache() then it force executes the executeQuery() for that VO to refresh the entity and view object cache from database.

There are two properties in your AM involving clearcahe:

1.clearCacheOnRollback - Whenever you do a AM rollback then all the underlying VO cache would be refreshed from DB, irrespective of any newly created rows.

Now, if you want to override this standard framework behavior then -

a). You need to override the following in the AMImpl Class:
     override afterRollback() and beforeRollback() methods and comment out the super() call.
     Write your own logic to do conditional/selective rollback of view objects.

b) The alternative approach of doing this could be -
   b1).As the AMImpl's rollback() internally calls individual  VO's Rollback() , so you can override the afterRollback() and beforeRollback() methods in VOImpl Class. Comment out the super() call and implement you logic to do conditional rollback for that VO.

This way, you can control the clearCache() for the specific VOs whose cache you want to retain even on AM rollback.

2.clearCacheOnCommit() - clearCache() on commit actually refreshes the entity and view object cache from database but at the same time it retains any newly created/ modified rows.

If you want to control the clearCache on Commit() then similarly you can overide the afterCommit() and beforeCommit() methods in resp VOImpl classes.

Transient View Object scenario:

For transient VO also the behavior is same but -

1.If you have set that "no rows has to be fetched" then the framework never force executes the executeQuery() even on clearCache(). This particular scenario I have encountered in the due course of development.

 - So, in this particular scenario when "no rows to be fetched" flag is set and you want to clear your transient VO cache before every progrmmatic population then you need to explictly call the VO.executeQuery(), so that it clears the underlying cache.

2.If the "no. of rows to be fetched" is non-zero then the clearCache() should force execute the VO query and your VO cache should be flushed out.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值