[ 
https://issues.apache.org/jira/browse/OFBIZ-5332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13781879#comment-13781879
 ] 

Adrian Crum commented on OFBIZ-5332:
------------------------------------

Thank you for the bug report. I am looking into it.

At first glance, it looks like the findOne method logic is flawed. We put 
GenericValue.NULL_VALUE in the primary key cache, but we never check for it 
when retrieving values from the cache.


> GenericDelegator failed to cache NULL_VALUE
> -------------------------------------------
>
>                 Key: OFBIZ-5332
>                 URL: https://issues.apache.org/jira/browse/OFBIZ-5332
>             Project: OFBiz
>          Issue Type: Bug
>          Components: framework
>    Affects Versions: SVN trunk
>            Reporter: Sam Ng
>            Assignee: Adrian Crum
>            Priority: Minor
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> GenericeDelegator should determine if the value is GenericValue.NULL_VALUE 
> inside findOne(), otherwise, NULL_VALUE will be considered as cache missed.
> And I have searched, although getFromPrimaryKeyCache() is public, but 
> findOne() is the caller, so it is safe to change it's behavior.
> According to my own test, if we fix this bug, about 1/3 of the DB queries 
> will be removed (cache hit).
>     public GenericValue findOne(String entityName, Map<String, ? extends 
> Object> fields, boolean useCache) throws GenericEntityException {
>         ....
>         if (useCache) {
>            ...
>             GenericValue value = this.getFromPrimaryKeyCache(primaryKey);
>             if (value != null) {
>                 //========== change the following two line ==========
>                 if ( value == GenericValue.NULL_VALUE ) return null; 
>                 else return value;
>             }
>         }
>     public GenericValue getFromPrimaryKeyCache(GenericPK primaryKey) {
>        .....
>         GenericValue value = cache.get(primaryKey);
>         //========== remove the following three lines ==========
>         // if (value == GenericValue.NULL_VALUE) {
>         //     return null;
>         //}
>         return value;
>     }



--
This message was sent by Atlassian JIRA
(v6.1#6144)

Reply via email to