ibatis-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Mathews (JIRA)" <ibatis-...@incubator.apache.org>
Subject [jira] Commented: (IBATIS-174) CacheModel does not support caching null results
Date Fri, 22 Jul 2005 06:26:47 GMT
    [ http://issues.apache.org/jira/browse/IBATIS-174?page=comments#action_12316448 ] 

Chris Mathews commented on IBATIS-174:

Sorry, in case my above comment isn't clear... the suggested code change is for com.ibatis.sqlmap.engine.cache.CacheModel.

> CacheModel does not support caching null results
> ------------------------------------------------
>          Key: IBATIS-174
>          URL: http://issues.apache.org/jira/browse/IBATIS-174
>      Project: iBatis for Java
>         Type: Bug
>   Components: SQL Maps
>     Versions: 2.0.9
>  Environment: All
>     Reporter: Chris Mathews
>  Attachments: CacheModelTest.java
> Currently IBatis caching does not support  caching null results.  Any null object placed
into the CacheModel will always result in what is interpertated as a cache miss when it is
looked up again.  When a null object put into the cache (by calling CacheModel.putObject())
it is actually entered into the cache as a CacheModel.NULL_OBJECT (which is fine).  However,
when the same object is retrieved (by calling CacheModel.getObject()) the CacheModel.NULL_OBJECT
is translated into an actual Java null value.  A null value being returned by CacheModel.getObject()
is considered a cache miss in the calling code (CachingStatement.executeQueryForList() and
CachingStatement.executeQueryForObject())... this is causing a hard hit to database unnecessarily.
> We are running into this problem while trying to cache a simple holiday table in one
of our applications.  The query takes a date a parameter and returns a row if the holiday
exists or null if it does not.  Since the vast majority of days are not holidays and therefore
return null, 95% of these statements are actually hitting the database and basically making
the cache for this query ineffective.
> The change to fix this appears to be very simple...
> Change line 289 from:
> return value == NULL_OBJECT ? null : value;
> To simply:
> return value;
> The code that calls CacheModel.getObject() in CachingStatement already checks to NULL_OBJECT
return values and handles them appropriately so it looks like this scenario has already been
thought through but possibly the above suggested change was missed.
> Attached is a test case that shows the defect and should pass once the above change is

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message