Object

com.twitter.cache

Refresh

Related Doc: package cache

Permalink

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.util.TimeConversions._ import com.twitter.cache.Refresh val getData: () => Future[T] = Refresh.every(1.hour) { ... }

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

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def every[T](ttl: Duration)(provider: ⇒ Future[T]): () ⇒ Future[T]

    Permalink

    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>>() {

    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

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  10. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  11. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  12. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  13. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  16. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  17. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  18. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped