Details
-
Bug
-
Status: To Do
-
Major
-
Resolution: Unresolved
-
0.1.0, 0.2.0
-
None
-
None
Description
The SafeUpdateCache Class needs to change the value in another thread when requesting the value from the cache instance.
With the above operation, the current thread should not be blocked.
However, due to the bug in the line below, the lazy value is evaluated unintentionally, causing the forground thread to block.
def withCache[T <: AnyRef](key: String, broadcast: Boolean, cacheTTLInSecs: Option[Int] = None, onEvict: AnyRef => Unit = defaultOnEvict)(op: => T): T = { ... ... if (running) cachedVal else { val value = op // Bug on this line: value must be declared as lazy val Future(value)(executionContext) onComplete { case Failure(ex) => put(key, cachedVal, false) logger.error(s"withCache update failed: $cacheKey", ex) case Success(newValue) => put(key, newValue, broadcast = (broadcast && newValue != cachedVal)) onEvict(cachedVal) cachedVal match { case None => case _ => logger.info(s"withCache update success: $cacheKey") } } cachedVal } } } }