com.sleepycat.je.rep.impl.node
Class DbCache

java.lang.Object
  extended by com.sleepycat.je.rep.impl.node.DbCache

public class DbCache
extends Object

Cache used to maintain DatabaseImpl handles. The cache retains some configurable number of MRU entries. In addition, the cache will discard MRU entries that have not been used within a configurable timeout period.

Implementation notes:


Constructor Summary
DbCache(DbTree dbTree, int maxEntries, int timeoutMs)
          Creates an instance of a DbCache.
 
Method Summary
 void clear()
          Clears out the cache releasing db handles as well
 DatabaseImpl get(DatabaseId dbId, Txn txn)
          Returns the DatabaseImpl associated with the dbId, caching the return value, if it's not already cached.
(package private)  LinkedHashMap<DatabaseId,com.sleepycat.je.rep.impl.node.DbCache.Info> getMap()
           
 int getMaxEntries()
          Returns the max entries that can be held by the cache.
 int getTimeoutMs()
          Returns the configured timeout in ms.
 void setConfig(RepConfigManager configMgr)
          Updates the configuration of the db cache, by resetting maxEntries and timeoutMs to the configured values.
 void tick()
          The tick() method forms the basis for removing stale entries from the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbCache

DbCache(DbTree dbTree,
        int maxEntries,
        int timeoutMs)
Creates an instance of a DbCache.

Parameters:
dbTree - the source of the data being cached
maxEntries - the max MRU entries to be retained in the cache
timeoutMs - the timeout used to remove stale entries. A timeout value of zero means that each call to tick() will move the "clock" forward. It's useful for testing purposes.
Method Detail

tick

public void tick()
The tick() method forms the basis for removing stale entries from the cache. It effectively advances the "clock" and removes any entries that have been rendered stale.


get

public DatabaseImpl get(DatabaseId dbId,
                        Txn txn)
Returns the DatabaseImpl associated with the dbId, caching the return value, if it's not already cached. The open triggers will be invoked if this was the first write reference.

Parameters:
dbId - the dbId that is to be resolved.
Returns:
the corresponding DatabaseImpl

setConfig

public void setConfig(RepConfigManager configMgr)
Updates the configuration of the db cache, by resetting maxEntries and timeoutMs to the configured values.

Note that setting the cache to a smaller max entry does not immediately reduce the number of entries currently in the cache, if the size of the cache is already at the maximum. The reduction will take place incrementally over time, as calls to "put" operations are made and DbCacheLinkedHashMap#removeEldestEntry is invoked for each put operation. This incremental cache size reduction is not expected to be a significant drawback in practice.

Parameters:
configMgr - the configuration holding the cache parameters

getMaxEntries

public int getMaxEntries()
Returns the max entries that can be held by the cache.


getTimeoutMs

public int getTimeoutMs()
Returns the configured timeout in ms. If a db handle has been inactive for a period of time that exceeds the timeout it's removed from the cache.


clear

public void clear()
Clears out the cache releasing db handles as well


getMap

LinkedHashMap<DatabaseId,com.sleepycat.je.rep.impl.node.DbCache.Info> getMap()


Copyright (c) 2004-2012 Oracle. All rights reserved.