Uploaded image for project: 'iBatis for .NET'
  1. iBatis for .NET
  2. IBATISNET-97

CacheModel does not support caching null results

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • DataMapper 1.2.1
    • DataMapper 1.3
    • DataMapper
    • None

    Description

      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; }

      }

      Attachments

        Activity

          People

            gilles Gilles Bayon
            ron liu ron
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: