Packages

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) { ... }

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Refresh
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  8. 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 operation that will refresh on invocation if more than ttl time has passed since operation was last called.

  9. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  10. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  12. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  14. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  16. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  17. def toString(): String
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  19. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  20. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Inherited from AnyRef

Inherited from Any

Ungrouped