Class TransactionalCache

java.lang.Object
org.apache.ibatis.cache.decorators.TransactionalCache
All Implemented Interfaces:
Cache

public class TransactionalCache
extends Object
implements Cache
The 2nd level cache transactional buffer.

This class holds all cache entries that are to be added to the 2nd level cache during a Session. Entries are sent to the cache when commit is called or discarded if the Session is rolled back. Blocking cache support has been added. Therefore any get() that returns a cache miss will be followed by a put() so any lock associated with the key can be released.

Author:
Clinton Begin, Eduardo Macarron
  • Constructor Details

    • TransactionalCache

      public TransactionalCache​(Cache delegate)
  • Method Details

    • getId

      public String getId()
      Specified by:
      getId in interface Cache
      Returns:
      The identifier of this cache
    • getSize

      public int getSize()
      Description copied from interface: Cache
      Optional. This method is not called by the core.
      Specified by:
      getSize in interface Cache
      Returns:
      The number of elements stored in the cache (not its capacity).
    • getObject

      public Object getObject​(Object key)
      Specified by:
      getObject in interface Cache
      Parameters:
      key - The key
      Returns:
      The object stored in the cache.
    • putObject

      public void putObject​(Object key, Object object)
      Specified by:
      putObject in interface Cache
      Parameters:
      key - Can be any object but usually it is a CacheKey
      object - The result of a select.
    • removeObject

      public Object removeObject​(Object key)
      Description copied from interface: Cache
      As of 3.3.0 this method is only called during a rollback for any previous value that was missing in the cache. This lets any blocking cache to release the lock that may have previously put on the key. A blocking cache puts a lock when a value is null and releases it when the value is back again. This way other threads will wait for the value to be available instead of hitting the database.
      Specified by:
      removeObject in interface Cache
      Parameters:
      key - The key
      Returns:
      Not used
    • clear

      public void clear()
      Description copied from interface: Cache
      Clears this cache instance.
      Specified by:
      clear in interface Cache
    • commit

      public void commit()
    • rollback

      public void rollback()