scalacache

package scalacache

Type members

Classlikes

trait AbstractCache[F[_], K, V] extends Cache[F, K, V] with LoggingSupport[F, K]

An abstract implementation of Cache that takes care of some things that are common across all concrete implementations.

An abstract implementation of Cache that takes care of some things that are common across all concrete implementations.

If you are writing a cache implementation, you probably want to extend this trait rather than extending Cache directly.

Type Params
K

The type of keys stored in the cache.

V

The type of values stored in the cache.

trait Cache[F[_], K, V]

Abstract algebra describing the operations a cache can perform

Abstract algebra describing the operations a cache can perform

Type Params
F

The effect monad in which all cache operations will be performed.

K

The type of keys stored in the cache.

V

The type of values stored in the cache.

trait CacheAlg[F[_], V]

Abstract algebra describing the operations a cache can perform

Abstract algebra describing the operations a cache can perform

Type Params
F

The effect monad in which all cache operations will be performed.

V

The value of types stored in the cache.

case
class Entry[+A](value: A, expiresAt: Option[Instant])

A cache entry with an optional expiry time

A cache entry with an optional expiry time

Companion
object
object Entry
Companion
class
case
class Flags(readsEnabled: Boolean, writesEnabled: Boolean)

Configuration flags for conditionally altering the behaviour of ScalaCache.

Configuration flags for conditionally altering the behaviour of ScalaCache.

Value Params
readsEnabled

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

writesEnabled

if false, cache PUTs will be skipped

Companion
object
object Flags
Companion
class
sealed

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

trait LoggingSupport[F[_], K]

Helper methods for logging

Helper methods for logging

case
object MD5 extends HashingAlgorithm

MD5 returns 32 character long hexadecimal hash strings

MD5 returns 32 character long hexadecimal hash strings

final
class RemoveAll[K, V]
case
object SHA1 extends HashingAlgorithm

SHA1 returns 40 character long hexadecimal hash strings

SHA1 returns 40 character long hexadecimal hash strings

case
object SHA256 extends HashingAlgorithm

SHA256 returns 64 character long hexadecimal hash strings

SHA256 returns 64 character long hexadecimal hash strings

case
object SHA512 extends HashingAlgorithm

SHA512 returns 128 character long hexadecimal hash strings

SHA512 returns 128 character long hexadecimal hash strings

Value members

Concrete methods

def caching[F[_], K, V](key: K)(ttl: Option[Duration])(f: => V)(implicit cache: Cache[F, K, V], flags: Flags): F[V]

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.

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.

Note: If ttl is set to None, the result will be stored in the cache indefinitely.

Type Params
F

The type of container in which the result will be wrapped. This is decided by the mode.

V

the type of the block's result

Value Params
cache

The cache

f

The block to run

flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

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

mode

The operation mode, which decides the type of container in which to wrap the result

ttl

The time-to-live to use when inserting into the cache. If specified, the cache entry will expire after this time has elapsed.

Returns

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

def cachingF[F[_], K, V](key: K)(ttl: Option[Duration])(f: => F[V])(implicit cache: Cache[F, K, V], flags: Flags): F[V]

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.

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.

Note: If ttl is set to None, the result will be stored in the cache indefinitely.

Type Params
F

The type of container in which the result will be wrapped. This is decided by the mode.

V

the type of the block's result

Value Params
cache

The cache

f

The block to run

flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

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

mode

The operation mode, which decides the type of container in which to wrap the result

ttl

The time-to-live to use when inserting into the cache. If specified, the cache entry will expire after this time has elapsed.

Returns

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

def get[F[_], K, V](key: K)(implicit cache: Cache[F, K, V], flags: Flags): F[Option[V]]

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

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

Type Params
F

The type of container in which the result will be wrapped. This is decided by the mode.

V

The type of the corresponding value

Value Params
cache

The cache

flags

Flags used to conditionally alter the behaviour of ScalaCache

mode

The operation mode, which decides the type of container in which to wrap the result

Returns

the value, if there is one

def put[F[_], K, V](key: K)(value: V, ttl: Option[Duration])(implicit cache: Cache[F, K, V], flags: Flags): F[Unit]

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.

Type Params
F

The type of container in which the result will be wrapped. This is decided by the mode.

V

The type of the corresponding value

Value Params
cache

The cache

flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

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

mode

The operation mode, which decides the type of container in which to wrap the result

ttl

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

value

the value to be cached

def remove[F[_], K, V](key: K)(implicit cache: Cache[F, K, V]): F[Unit]

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

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.

Type Params
F

The type of container in which the result will be wrapped. This is decided by the mode.

V

The type of the value to be removed

Value Params
cache

The cache

keyParts

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

mode

The operation mode, which decides the type of container in which to wrap the result

def removeAll[K, V]: RemoveAll[K, V]

Remove all values from the cache.

Remove all values from the cache.

Type Params
V

The type of values to be removed