object Refresh
A single-value asynchronous cache with TTL. The provider supplies the future value when invoked
and this class ensures that the provider is not invoked more frequently than the TTL. If the
future fails, that failure is not cached. If more than one value is required, a FutureCache
backed by a Caffeine cache with TTL may be more appropriate.
This is useful in situations where a call to an external service returns a value that changes infrequently and we need to access that value often, for example asking a service for a list of features that it supports.
A non-memoized function like this: def getData(): Future[T] = { ... }
can be memoized with a TTL of 1 hour as follows: import com.twitter.conversions.DurationOps._ import com.twitter.cache.Refresh val getData: () => Future[T] = Refresh.every(1.hour) { ... }
- Alphabetic
- By Inheritance
- Refresh
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
every[T](ttl: Duration)(provider: ⇒ Future[T]): () ⇒ Future[T]
Create a memoized future with TTL.
Create a memoized future with TTL.
From Scala: Refresh.every(1.hour) { ... }
From Java: Refresh.every(Duration.fromSeconds(3600), new Function0<Future<T>>() { \@Override public Future<T> apply() { ... } });
- ttl
The amount of time between refreshes
- provider
A provider function that returns a future to refresh
- returns
A memoized version of
operationthat will refresh on invocation if more thanttltime has passed sinceoperationwas last called.
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()