• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

blemale / scaffeine / 13609192146

01 Mar 2025 10:00PM UTC coverage: 96.97%. Remained the same
13609192146

push

web-flow
Merge pull request #432 from scala-steward/update/scalafmt-core-3.9.2

Update scalafmt-core to 3.9.2

96 of 99 relevant lines covered (96.97%)

2.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/main/scala/com/github/blemale/scaffeine/AsyncLoadingCache.scala
1
package com.github.blemale.scaffeine
2

3
import com.github.benmanes.caffeine.cache.{AsyncLoadingCache => CaffeineAsyncLoadingCache}
4

5
import scala.collection.JavaConverters._
6
import scala.compat.java8.FutureConverters._
7
import scala.concurrent.{ExecutionContext, Future}
8

9
object AsyncLoadingCache {
10

11
  def apply[K, V](
12
      asyncLoadingCache: CaffeineAsyncLoadingCache[K, V]
13
  ): AsyncLoadingCache[K, V] =
14
    new AsyncLoadingCache(asyncLoadingCache)
2✔
15

16
}
17

18
class AsyncLoadingCache[K, V](
19
    override val underlying: CaffeineAsyncLoadingCache[K, V]
20
) extends AsyncCache[K, V](underlying) {
21
  implicit private[this] val ec: ExecutionContext = DirectExecutionContext
22

23
  /** Returns the future associated with `key` in this cache, obtaining that
24
    * value from `loader` if necessary. If the asynchronous computation fails,
25
    * the entry will be automatically removed.
26
    *
27
    * @param key
28
    *   key with which the specified value is to be associated
29
    * @return
30
    *   the current (existing or computed) future value associated with the
31
    *   specified key
32
    * @throws java.lang.RuntimeException
33
    *   or Error if the `loader` does when constructing the future, in which
34
    *   case the mapping is left unestablished
35
    */
36
  def get(key: K): Future[V] =
37
    underlying.get(key).toScala
2✔
38

39
  /** Returns the future of a map of the values associated with `keys`, creating
40
    * or retrieving those values if necessary. The returned map contains entries
41
    * that were already cached, combined with newly loaded entries. If the any
42
    * of the asynchronous computations fail, those entries will be automatically
43
    * removed.
44
    *
45
    * @param keys
46
    *   the keys whose associated values are to be returned
47
    * @return
48
    *   the future containing an mapping of keys to values for the specified
49
    *   keys in this cache
50
    * @throws java.lang.RuntimeException
51
    *   or Error if the `loader` does so
52
    */
53
  def getAll(keys: Iterable[K]): Future[Map[K, V]] =
54
    underlying.getAll(keys.asJava).toScala.map(_.asScala.toMap)
2✔
55

56
  /** Returns a view of the entries stored in this cache as a synchronous
57
    * [[LoadingCache]]. A mapping is not present if the value is currently being
58
    * loaded. Modifications made to the synchronous cache directly affect the
59
    * asynchronous cache. If a modification is made to a mapping that is
60
    * currently loading, the operation blocks until the computation completes.
61
    *
62
    * @return
63
    *   a thread-safe synchronous view of this cache
64
    */
65
  override def synchronous(): LoadingCache[K, V] =
66
    LoadingCache(underlying.synchronous())
2✔
67

68
  override def toString = s"AsyncLoadingCache($underlying)"
69
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc