Skip to content
This repository was archived by the owner on Mar 2, 2022. It is now read-only.

Commit 5e4d2fb

Browse files
committed
Added Mono.cache(ttl)
1 parent b9f2c50 commit 5e4d2fb

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/main/scala/reactor/core/scala/publisher/Mono.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ class Mono[T] private(private val jMono: JMono[T]) extends Publisher[T] with Map
165165
*
166166
* @return a replaying [[Mono]]
167167
*/
168-
final def cache(): Mono[T] = Mono[T](
169-
jMono.cache()
170-
)
168+
final def cache(): Mono[T] = Mono[T](jMono.cache())
169+
170+
final def cache(ttl: Duration) = Mono(jMono.cache(ttl))
171171

172172
/**
173173
* Prepare this [[Mono]] so that subscribers will cancel from it on a

src/test/scala/reactor/core/scala/publisher/MonoTest.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,17 @@ class MonoTest extends FreeSpec with Matchers with TableDrivenPropertyChecks wit
412412
number shouldBe a[ScalaNumber]
413413
}
414414

415-
".cache should call the underlying cache method" in {
416-
val jMono = spy(JMono.just(1))
417-
Mono(jMono).cache()
418-
Mockito.verify(jMono).cache()
415+
".cache" - {
416+
"should call the underlying cache method" in {
417+
val jMono = spy(JMono.just(1))
418+
Mono(jMono).cache()
419+
Mockito.verify(jMono).cache()
420+
}
421+
"with ttl should call the underlying cache method" in {
422+
val jMono = spy(JMono.just(1))
423+
Mono(jMono).cache(10 seconds)
424+
Mockito.verify(jMono).cache(10 seconds)
425+
}
419426
}
420427

421428
".cancelOn should cancel the subscriber on a particular scheduler" in {

0 commit comments

Comments
 (0)