CacheModel does not support caching null results
------------------------------------------------
Key: IBATISNET-97
URL: http://issues.apache.org/jira/browse/IBATISNET-97
Project: iBatis for .NET
Type: Bug
Components: DataMapper
Versions: DataMapper 1.2.1
Reporter: Ron Grabowski
Priority: Minor
When caching is enabled and the sqlMap.QueryForObject method returns a null
value, that null value is not cached. Subsequent calls to sqlMap.QueryForObject
always miss the cache and query the database. For more information see the Java
ticket of the same issue:
http://issues.apache.org/jira/browse/IBATIS-174
One solution is to define a special marker object in CacheModel.cs:
/// <summary>
/// Marked object to allow null objects to be cached
/// </summary>
[NonSerialized]
public readonly static object NULL_OBJECT = new Object();
and insert that value into the cache when a null value is returned from the
initial query.
The code to retrieve an item from the cache in MappedStatement.cs:
if (obj == null)
{
obj = RunQueryForObject(request, session, parameterObject, resultObject);
_statement.CacheModel[key] = obj;
}
could be changed to this:
// check if this query has alreay been run
if (obj == CacheModel.NULL_OBJECT)
{
// convert the marker object back into a null value
obj = null;
}
else if (obj == null)
{
obj = RunQueryForObject(request, session, parameterObject, resultObject);
if (obj == null)
{
// store null value in cache using the special marker object
_statement.CacheModel[key] = CacheModel.NULL_OBJECT;
}
else
{
// query returned a normal, non-null value
_statement.CacheModel[key] = obj;
}
}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira