Uploaded image for project: 'iBatis for Java [READ ONLY]'
  1. iBatis for Java [READ ONLY]
  2. IBATIS-724

Performance inefficiency using org.apache.ibatis.cache.Cache#hasKey

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0 Beta 7
    • 3.0 Beta 8
    • Core
    • None

    Description

      The use for a key check is potentially dangerous, as it may expire between checking for the key, and whatever you want to do with the stored object, and produce a race condition.

      I suggest to remove org.apache.ibatis.cache.Cache#hasKey method and let to the layer built on top of cache interface checking if the retrieved object is not null.
      For example (meta-code):

       if (cache.hasKey(key)) {
                    return (List) cache.getObject(key);
      }...
      

      Becomes:

      Object value = cache.getObject(key)
      if (value != null) {
          return  Cache.NULL_OBJECT.equals(value) ? null : value;
      }
      

      Where Cache.NULL_OBJECT value represents the difference between "yes I'm cached, and I'm null" vs. "I'm not cached".

      Attachments

        Activity

          People

            cbegin Clinton Begin
            simone.tripodi Simone Tripodi
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: