diff options
author | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-14 22:59:05 -0400 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-03-19 21:13:49 -0400 |
commit | 48780e341b8c094548641ba986f8a2b77f10d1da (patch) | |
tree | 6e35e03a74e9052bf299d4387fd121622915cec9 /stage1 | |
parent | 7eacad3bc48412521508999e97e38d4a494dc2ca (diff) | |
download | cbt-48780e341b8c094548641ba986f8a2b77f10d1da.tar.gz cbt-48780e341b8c094548641ba986f8a2b77f10d1da.tar.bz2 cbt-48780e341b8c094548641ba986f8a2b77f10d1da.zip |
minor refactorings of KeyLockedLazyCache
Diffstat (limited to 'stage1')
-rw-r--r-- | stage1/ClassLoaderCache.scala | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/stage1/ClassLoaderCache.scala b/stage1/ClassLoaderCache.scala index 05589d1..d303da3 100644 --- a/stage1/ClassLoaderCache.scala +++ b/stage1/ClassLoaderCache.scala @@ -23,21 +23,21 @@ Locking occurs on the key, so separate keys can be looked up simultaneously without a deadlock. */ final private[cbt] class KeyLockedLazyCache[Key <: AnyRef,Value <: AnyRef]( - keys: ConcurrentHashMap[Key,AnyRef], - builds: ConcurrentHashMap[AnyRef,Value], + val keys: ConcurrentHashMap[Key,AnyRef], + val values: ConcurrentHashMap[AnyRef,Value], logger: Option[Logger] ){ def get( key: Key, value: => Value ): Value = { - val keyObject = keys.synchronized{ + val lockableKey = keys.synchronized{ if( ! (keys containsKey key) ){ - val keyObject = new LockableKey - logger.foreach(_.resolver("CACHE MISS: " ++ key.toString)) - keys.put( key, keyObject ) - keyObject + val lockableKey = new LockableKey + //logger.foreach(_.resolver("CACHE MISS: " ++ key.toString)) + keys.put( key, lockableKey ) + lockableKey } else { - val keyObject = keys get key - logger.foreach(_.resolver("CACHE HIT: " ++ keyObject.toString ++ " -> " ++ key.toString)) - keyObject + val lockableKey = keys get key + //logger.foreach(_.resolver("CACHE HIT: " ++ lockableKey.toString ++ " -> " ++ key.toString)) + lockableKey } } import collection.JavaConversions._ @@ -45,18 +45,17 @@ final private[cbt] class KeyLockedLazyCache[Key <: AnyRef,Value <: AnyRef]( // synchronizing on key only, so asking for a particular key does // not block the whole cache, but just that cache entry key.synchronized{ - if( ! (builds containsKey keyObject) ){ - builds.put( keyObject, value ) + if( ! (values containsKey lockableKey) ){ + values.put( lockableKey, value ) } - builds get keyObject + values get lockableKey } } def remove( key: Key ) = keys.synchronized{ - if( (keys containsKey key) ){ - keys.put( key, new LockableKey ) - } - val keyObject = keys get key + assert(keys containsKey key) + val lockableKey = keys get key keys.remove( key ) - builds.remove( keyObject ) + assert(values containsKey lockableKey) + values.remove( lockableKey ) } } |