aboutsummaryrefslogtreecommitdiff
path: root/stage1/KeyLockedLazyCache.scala
diff options
context:
space:
mode:
Diffstat (limited to 'stage1/KeyLockedLazyCache.scala')
-rw-r--r--stage1/KeyLockedLazyCache.scala33
1 files changed, 0 insertions, 33 deletions
diff --git a/stage1/KeyLockedLazyCache.scala b/stage1/KeyLockedLazyCache.scala
deleted file mode 100644
index c8b37ea..0000000
--- a/stage1/KeyLockedLazyCache.scala
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
-package cbt
-import java.util.concurrent.ConcurrentHashMap
-import scala.concurrent.Future
-
-/**
-A cache that lazily computes values if needed during lookup.
-Locking occurs on the key, so separate keys can be looked up
-simultaneously without a deadlock.
-*/
-final private[cbt] class KeyLockedLazyCache[Key <: AnyRef,Value]{
- private val keys = new ConcurrentHashMap[Key,LockableKey]()
- private val builds = new ConcurrentHashMap[LockableKey,Value]()
-
- private class LockableKey
- def get( key: Key, value: => Value ): Value = {
- val keyObject = keys.synchronized{
- if( ! (keys containsKey key) ){
- keys.put( key, new LockableKey )
- }
- keys get key
- }
- // 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 )
- }
- builds get keyObject
- }
- }
-}
-*/