Package

scalacache

Permalink

package scalacache

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. scalacache
  2. JavaSerializationCodec
  3. AnyRef
  4. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. trait Cache[Repr] extends AnyRef

    Permalink
  2. case class CacheConfig(keyPrefix: Option[String] = None, keySeparator: String = ":", waitForWriteToComplete: Boolean = true) extends Product with Serializable

    Permalink

    Configuration options for ScalaCache

    Configuration options for ScalaCache

    keyPrefix

    A global prefix that should be prepended to all cache keys. Useful for namespacing if you are sharing your cache with another application.

    keySeparator

    The value used to separate different parts of a cache key

    waitForWriteToComplete

    If true, the Future returned by caching (or memoize) will not complete until the cache write has completed. If false, the Future will complete as soon as the value has been computed, and the cache write will happen asynchronously. The latter was the behaviour until ScalaCache 0.9.2, but the former is more useful in many situations.

  3. trait CacheKeyBuilder extends AnyRef

    Permalink
  4. case class Entry[+A](value: A, expiresAt: Option[DateTime]) extends Product with Serializable

    Permalink

    A cache entry with an optional expiry time

  5. case class Flags(readsEnabled: Boolean = true, writesEnabled: Boolean = true) extends Product with Serializable

    Permalink

    Configuration flags for conditionally altering the behaviour of ScalaCache.

    Configuration flags for conditionally altering the behaviour of ScalaCache.

    readsEnabled

    if false, cache GETs will be skipped (and will return None)

    writesEnabled

    if false, cache PUTs will be skipped

  6. sealed trait HashingAlgorithm extends AnyRef

    Permalink

    Sealed HashingAlgorithm trait to prevent users from shooting themselves in the foot at runtime by specifying a crappy/unsupported algorithm name

    Sealed HashingAlgorithm trait to prevent users from shooting themselves in the foot at runtime by specifying a crappy/unsupported algorithm name

    The name should be a valid MessageDigest algorithm name.Implementing child classes/objects should refer to this list for proper names:

    http://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#MessageDigest

  7. trait LoggingSupport extends AnyRef

    Permalink

    Helper methods for logging

  8. type NoSerialization = InMemoryRepr

    Permalink
  9. case class ScalaCache[Repr](cache: Cache[Repr], cacheConfig: CacheConfig = CacheConfig(), keyBuilder: CacheKeyBuilder = DefaultCacheKeyBuilder, memoization: MemoizationConfig = MemoizationConfig()) extends Product with Serializable

    Permalink

    Container holding the cache itself, along with all necessary configuration.

    Container holding the cache itself, along with all necessary configuration.

    cache

    The cache itself

    memoization

    Configuration related to method memoization

  10. class TypedApi[From, Repr] extends AnyRef

    Permalink

Value Members

  1. implicit def AnyRefBinaryCodec[S <: Serializable](implicit ev: ClassTag[S]): Codec[S, Array[Byte]]

    Permalink

    Uses plain Java serialization to deserialize objects

    Uses plain Java serialization to deserialize objects

    Definition Classes
    JavaSerializationCodec
  2. object DefaultCacheKeyBuilder extends CacheKeyBuilder

    Permalink
  3. object Flags extends Serializable

    Permalink
  4. object MD5 extends HashingAlgorithm with Product with Serializable

    Permalink

    MD5 returns 32 character long hexadecimal hash strings

  5. object SHA1 extends HashingAlgorithm with Product with Serializable

    Permalink

    SHA1 returns 40 character long hexadecimal hash strings

  6. object SHA256 extends HashingAlgorithm with Product with Serializable

    Permalink

    SHA256 returns 64 character long hexadecimal hash strings

  7. object SHA512 extends HashingAlgorithm with Product with Serializable

    Permalink

    SHA512 returns 128 character long hexadecimal hash strings

  8. def caching[V, Repr](keyParts: Any*)(f: ⇒ Future[V])(implicit scalaCache: ScalaCache[Repr], flags: Flags, execContext: ExecutionContext = ExecutionContext.global, codec: Codec[V, Repr]): Future[V]

    Permalink

    Wrap the given block with a caching decorator.

    Wrap the given block with a caching decorator. First look in the cache. If the value is found, then return it immediately. Otherwise run the block and save the result in the cache before returning it.

    All of the above happens asynchronously, so a Future is returned immediately. Specifically: - when the cache lookup completes, if it is a miss, the block execution is started. - at some point after the block execution completes, the result is written asynchronously to the cache. - the Future returned from this method does not wait for the cache write before completing.

    Note: Because no TTL is specified, the result will be stored in the cache indefinitely.

    V

    the type of the block's result

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

    f

    the block to run

    returns

    the result, either retrived from the cache or returned by the block

  9. def cachingForMemoize[V, Repr](key: String)(optionalTtl: Option[Duration])(f: ⇒ Future[V])(implicit scalaCache: ScalaCache[Repr], flags: Flags, execContext: ExecutionContext = ExecutionContext.global, codec: Codec[V, Repr]): Future[V]

    Permalink
  10. def cachingWithOptionalTTL[V, Repr](keyParts: Any*)(optionalTtl: Option[Duration])(f: ⇒ Future[V])(implicit scalaCache: ScalaCache[Repr], flags: Flags, execContext: ExecutionContext = ExecutionContext.global, codec: Codec[V, Repr]): Future[V]

    Permalink
  11. def cachingWithTTL[V, Repr](keyParts: Any*)(ttl: Duration)(f: ⇒ Future[V])(implicit scalaCache: ScalaCache[Repr], flags: Flags, execContext: ExecutionContext = ExecutionContext.global, codec: Codec[V, Repr]): Future[V]

    Permalink

    Wrap the given block with a caching decorator.

    Wrap the given block with a caching decorator. First look in the cache. If the value is found, then return it immediately. Otherwise run the block and save the result in the cache before returning it.

    All of the above happens asynchronously, so a Future is returned immediately. Specifically: - when the cache lookup completes, if it is a miss, the block execution is started. - at some point after the block execution completes, the result is written asynchronously to the cache. - the Future returned from this method does not wait for the cache write before completing.

    The result will be stored in the cache until the given TTL expires.

    V

    the type of the block's result

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

    ttl

    Time To Live

    f

    the block to run

    returns

    the result, either retrived from the cache or returned by the block

  12. def get[V, Repr](keyParts: Any*)(implicit scalaCache: ScalaCache[Repr], flags: Flags, codec: Codec[V, Repr]): Future[Option[V]]

    Permalink

    Get the value corresponding to the given key from the cache.

    Get the value corresponding to the given key from the cache.

    Depending on the cache implementation, this may be done synchronously or asynchronously, so it returns a Future.

    V

    the type of the corresponding value

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

    returns

    the value, if there is one

  13. package memoization

    Permalink

    Utilities for memoizing the results of method calls in a cache.

    Utilities for memoizing the results of method calls in a cache. The cache key is generated from the method arguments using a macro, so that you don't have to bother passing them manually.

  14. def put[V, Repr](keyParts: Any*)(value: V, ttl: Option[Duration] = None)(implicit scalaCache: ScalaCache[Repr], flags: Flags, codec: Codec[V, Repr]): Future[Unit]

    Permalink

    Insert the given key-value pair into the cache, with an optional Time To Live.

    Insert the given key-value pair into the cache, with an optional Time To Live.

    Depending on the cache implementation, this may be done synchronously or asynchronously, so it returns a Future.

    V

    the type of the corresponding value

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

    value

    the value to be cached

    ttl

    Time To Live (optional, if not specified then the entry will be cached indefinitely)

  15. def remove(keyParts: Any*)(implicit scalaCache: ScalaCache[_]): Future[Unit]

    Permalink

    Remove the given key and its associated value from the cache, if it exists.

    Remove the given key and its associated value from the cache, if it exists. If the key is not in the cache, do nothing.

    Depending on the cache implementation, this may be done synchronously or asynchronously, so it returns a Future.

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

  16. def removeAll()(implicit scalaCache: ScalaCache[_]): Future[Unit]

    Permalink

    Delete the entire contents of the cache.

    Delete the entire contents of the cache. Use wisely!

  17. package serialization

    Permalink
  18. object sync

    Permalink

    Synchronous API, for the case when you don't want to deal with Futures.

  19. def typed[V, Repr](implicit scalaCache: ScalaCache[Repr], codec: Codec[V, Repr]): TypedApi[V, Repr]

    Permalink

    Create an instance of the 'typed' API that limits use of the cache to a single type.

    Create an instance of the 'typed' API that limits use of the cache to a single type.

    This means you can't accidentally put something of the wrong type into your cache, and it reduces keystrokes because you don't need to specify types when calling get, put, etc.

    e.g.

    import scalacache._
    implicit val sc: ScalaCache = ...
    
    val intCache = typed[Int]
    
    intCache.put("one")(1) // OK
    intCache.put("two")(2.0) // Nope! Compiler error
    
    val one = intCache.get("1") // returns a Future[Option[Int]]
    V

    the type of values that the cache will accept

Deprecated Value Members

  1. def getSync[V, Repr](keyParts: Any*)(implicit scalaCache: ScalaCache[Repr], flags: Flags, codec: Codec[V, Repr]): Option[V]

    Permalink

    Convenience method to get a value from the cache synchronously.

    Convenience method to get a value from the cache synchronously.

    Warning: may block indefinitely!

    V

    the type of the corresponding value

    keyParts

    data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.

    returns

    the value, if there is one

    Annotations
    @deprecated
    Deprecated

    (Since version 0.7.0) This method has moved. Please use scalacache.sync.get

Inherited from JavaSerializationCodec

Inherited from AnyRef

Inherited from Any

Ungrouped