Package org.h2.util

Class CacheSecondLevel

  • All Implemented Interfaces:
    Cache

    class CacheSecondLevel
    extends java.lang.Object
    implements Cache
    Cache which wraps another cache (proxy pattern) and adds caching using map. This is useful for WeakReference, SoftReference or hard reference cache.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Cache baseCache  
      private java.util.Map<java.lang.Integer,​CacheObject> map  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clear the cache.
      CacheObject find​(int pos)
      Get an element from the cache if it is available.
      CacheObject get​(int pos)
      Get an element in the cache if it is available.
      java.util.ArrayList<CacheObject> getAllChanged()
      Get all objects in the cache that have been changed.
      int getMaxMemory()
      Get the maximum memory to be used.
      int getMemory()
      Get the used size in KB.
      void put​(CacheObject r)
      Add an element to the cache.
      boolean remove​(int pos)
      Remove an object from the cache.
      void setMaxMemory​(int size)
      Set the maximum memory to be used by this cache.
      CacheObject update​(int pos, CacheObject record)
      Update an element in the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • baseCache

        private final Cache baseCache
      • map

        private final java.util.Map<java.lang.Integer,​CacheObject> map
    • Constructor Detail

      • CacheSecondLevel

        CacheSecondLevel​(Cache cache,
                         java.util.Map<java.lang.Integer,​CacheObject> map)
    • Method Detail

      • clear

        public void clear()
        Description copied from interface: Cache
        Clear the cache.
        Specified by:
        clear in interface Cache
      • find

        public CacheObject find​(int pos)
        Description copied from interface: Cache
        Get an element from the cache if it is available. This will not move the item to the front of the list.
        Specified by:
        find in interface Cache
        Parameters:
        pos - the unique key of the element
        Returns:
        the element or null
      • get

        public CacheObject get​(int pos)
        Description copied from interface: Cache
        Get an element in the cache if it is available. This will move the item to the front of the list.
        Specified by:
        get in interface Cache
        Parameters:
        pos - the unique key of the element
        Returns:
        the element or null
      • getAllChanged

        public java.util.ArrayList<CacheObject> getAllChanged()
        Description copied from interface: Cache
        Get all objects in the cache that have been changed.
        Specified by:
        getAllChanged in interface Cache
        Returns:
        the list of objects
      • getMaxMemory

        public int getMaxMemory()
        Description copied from interface: Cache
        Get the maximum memory to be used.
        Specified by:
        getMaxMemory in interface Cache
        Returns:
        the maximum size in KB
      • getMemory

        public int getMemory()
        Description copied from interface: Cache
        Get the used size in KB.
        Specified by:
        getMemory in interface Cache
        Returns:
        the current size in KB
      • put

        public void put​(CacheObject r)
        Description copied from interface: Cache
        Add an element to the cache. Other items may fall out of the cache because of this. It is not allowed to add the same record twice.
        Specified by:
        put in interface Cache
        Parameters:
        r - the object
      • remove

        public boolean remove​(int pos)
        Description copied from interface: Cache
        Remove an object from the cache.
        Specified by:
        remove in interface Cache
        Parameters:
        pos - the unique key of the element
        Returns:
        true if the key was in the cache
      • setMaxMemory

        public void setMaxMemory​(int size)
        Description copied from interface: Cache
        Set the maximum memory to be used by this cache.
        Specified by:
        setMaxMemory in interface Cache
        Parameters:
        size - the maximum size in KB
      • update

        public CacheObject update​(int pos,
                                  CacheObject record)
        Description copied from interface: Cache
        Update an element in the cache. This will move the item to the front of the list.
        Specified by:
        update in interface Cache
        Parameters:
        pos - the unique key of the element
        record - the element
        Returns:
        the element