Enum Class CacheManager

java.lang.Object
java.lang.Enum<CacheManager>
chemaxon.jchem.db.cache.CacheManager
All Implemented Interfaces:
chemaxon.jchem.db.cache.CacheManagerMXBean, Serializable, Comparable<CacheManager>, java.lang.constant.Constable

@PublicAPI public enum CacheManager extends Enum<CacheManager> implements chemaxon.jchem.db.cache.CacheManagerMXBean
Singleton for managing cache-related functions. Object available as CacheManager.INSTANCE.
Since:
6.0
  • Enum Constant Details

  • Method Details

    • values

      public static CacheManager[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CacheManager valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • setPinCacheDefaultValue

      public void setPinCacheDefaultValue(boolean pinCacheDefaultValue)
      Sets the default pin behavior of loading cache. It relates to both automatically and manually loaded caches.
      Parameters:
      pinCacheDefaultValue - set the new default value
      Since:
      6.0
      See Also:
    • getPinCacheDefaultValue

      public boolean getPinCacheDefaultValue()
      Gets the default pin behavior of loading cache.
      Returns:
      the default behavior of pinning cache when loading cache
      Since:
      6.0
      See Also:
    • loadCache

      public void loadCache(ConnectionHandler connectionHandler, String tableName, boolean haltOnError, boolean pinCache) throws Exception
      Loads or updates cache directly into memory without making a (first) search in the table.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to load into the cache
      haltOnError - if true, stops on any errors during loading; tries to recover otherwise
      pinCache - if set to true, the cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached. Otherwise it is thrown out in that case.
      Throws:
      Exception - depending on the haltOnError setting, it may throw an exception
      Since:
      6.0
    • loadCache

      public void loadCache(ConnectionHandler connectionHandler, String tableName, boolean haltOnError) throws Exception
      Loads or updates cache directly into memory without making a (first) search in the table.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to load into the cache
      haltOnError - if true, stops on any errors during loading; tries to recover otherwise
      Throws:
      Exception - depending on the haltOnError setting, it may throw an exception
      Since:
      6.0
    • loadCache

      public void loadCache(ConnectionHandler connectionHandler, String tableName, String indexedTable, String indexedColumn, boolean haltOnError, boolean pinCache) throws Exception
      For internal use only.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to load into the cache
      indexedTable - the name of the table
      indexedColumn - the name of the indexed column
      haltOnError - if true, stops on any errors during loading; tries to recover otherwise.
      pinCache - if true, the cache is pinned
      Throws:
      Exception - whatever
    • pinCache

      public void pinCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException
      Pins cache into memory. The cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to be pinned into the cache
      Throws:
      Exception - depending on the haltOnError setting, it may throw an exception
      IllegalArgumentException - if no cache is loaded into memory for the structure table
      Since:
      6.0
    • unpinCache

      public void unpinCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException
      Unpins cache from memory without making a (first) search in the table. The cache is pinned into memory and won't be released when physical memory is deemed insufficient to hold an additional structure table cached.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to be pinned into the cache
      Throws:
      Exception - depending on the haltOnError setting, it may throw an exception
      IllegalArgumentException - if no cache is loaded into memory for the structure table
      Since:
      6.0
    • findCache

      public chemaxon.jchem.db.cache.JChemCache findCache(ConnectionHandler ch, String tableName, boolean cartridgeMode) throws chemaxon.jchem.base.storage.PersistenceException
      For internal use only.
      Parameters:
      ch - the connection to use
      tableName - the name of the table
      cartridgeMode - true if cartridge
      Returns:
      a cache responsible for the table
      Throws:
      chemaxon.jchem.base.storage.PersistenceException - if some error occurs
    • getCacheRemovalMethod

      public chemaxon.jchem.db.cache.CacheRemovalMethod getCacheRemovalMethod()
      For internal use only.
      Returns:
      the current cacheRemovalMethod
    • setCacheRemovalMethod

      public void setCacheRemovalMethod(chemaxon.jchem.db.cache.CacheRemovalMethod cacheRemovalMethod)
      For internal use only.
      Parameters:
      cacheRemovalMethod - the removalmethod to use
    • unloadCache

      public void unloadCache(ConnectionHandler connectionHandler, String tableName, boolean cartridgeMode, boolean haltOnError) throws chemaxon.jchem.base.storage.PersistenceException
      For internal use only.
      Parameters:
      connectionHandler - connection handler to use
      tableName - the name of the table
      cartridgeMode - true if used from cartridge
      haltOnError - haltonerror state
      Throws:
      chemaxon.jchem.base.storage.PersistenceException - if it encounter some problem
    • unloadCache

      public void unloadCache(ConnectionHandler connectionHandler, String tableName) throws Exception, IllegalArgumentException
      Unloads cache from the memory. This can be useful when the server is low on memory and an unused table is loaded into memory.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to unload from cache
      Throws:
      Exception - if some error is encountered.
      IllegalArgumentException - if no cache is loaded into memory for the structure table
      Since:
      6.0
    • isCacheLoaded

      public boolean isCacheLoaded(ConnectionHandler connectionHandler, String tableName) throws Exception
      Returns whether the cache is loaded. If the cache load has been started, but it isn't finished yet, the function returns false. Be aware that when changes are made in the table, the cache needs to be updated. So despite this function returning true, the next search may be slower than usual.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to look for
      Returns:
      true if cache is loaded
      Throws:
      Exception - if some error is encountered.
      Since:
      6.0
    • isCacheLoadStarted

      public boolean isCacheLoadStarted(ConnectionHandler connectionHandler, String tableName) throws Exception
      Returns whether the cache is loaded or cache load has been started.
      Parameters:
      connectionHandler - ConnectionHandler with live connection
      tableName - the name of the structure table to look for
      Returns:
      true if cache is loaded or the cache load has been started
      Throws:
      Exception - if some error is encountered.
      Since:
      6.0
    • setMaxCacheSize

      public void setMaxCacheSize(int maxCacheSizeMB)
      Sets the desired cache memory allocation policy.
      NOTE: the current cache size won't change automatically, only during next cache load or update event. If set to -1 (auto-detect) or minFreeMem is not set to 0, the program tries to determine the maximum amount of memory available for allocation by calling the garbage collector and determining the available memory.
      NOTE: Under Java Runtime Environment 1.3.1 or older the available memory size cannot be determined. In this case JChem allocates cache for tables until it detects OutOfMemoryError during loading.
      Parameters:
      maxCacheSizeMB - the maximum amount of memory the cache allowed to utilize in megabytes. Set -1 for auto-detection (default): maxCacheSize = available_memory - minFreeMem
      Since:
      6.1
      See Also:
    • setMinNonCachedMemory

      public void setMinNonCachedMemory(int minNonCachedMemoryMB)
      Sets the desired cache memory allocation policy.
      NOTE: the current cache size won't change automatically, only during next cache load or update event. If not set to 0 or maxCacheSize is set to -1 (auto-detect), the program tries to determine the maximum amount of memory available for allocation by calling the garbage collector and determining the available memory.
      NOTE: Under Java Runtime Environment 1.3.1 or older the available memory size cannot be determined. In this case JChem allocates cache for tables until it detects OutOfMemoryError during loading.
      Parameters:
      minNonCachedMemoryMB - the minimum amount of memory that should be left free for future non-cache allocations in megabytes.
      Set to 0 if not specified.
      Set to -1 for auto-detection (default):
      • 10 % of all available space for future allocations
      • Not smaller, than 250 MB
      • Nor bigger, than 1000 MB
      Since:
      6.1
      See Also:
    • getCachedTables

      public Hashtable<String,Long> getCachedTables()
      Gets the names and sizes of tables currently in the cache.
      Returns:
      the names and allocated memory size in bytes as key - value (String - Long) pairs.
      Since:
      6.1
    • clearCache

      public void clearCache()
      Clears the cache that stores fingerprints and structures.
      Since:
      6.1
    • setCacheExpirationTime

      public void setCacheExpirationTime(double hours)
      Sets the expiration time for the structure cache. At the start of each search all tables are purged from cache that were searched before the specified time period. Naturally the currently searched tables are never purged.
      Parameters:
      hours - the time in hours. The default value is 0. Set to 0 for no expiration.
      Since:
      6.1
      See Also: