CacheAlg

trait CacheAlg[F[_], V]

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.

class Object
trait Matchable
class Any
trait Cache[F, V]
trait AbstractCache[F, V]

Value members

Abstract methods

def caching(keyParts: Any*)(ttl: Option[Duration])(f: => V)(implicit flags: Flags): F[V]

Get a value from the cache if it exists. Otherwise compute it, insert it into the cache, and return it.

Get a value from the cache if it exists. Otherwise compute it, insert it into the cache, and return it.

Value Params
f

A block that computes the value

flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

The cache key

ttl

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

Returns

The value, either retrieved from the cache or computed

def cachingF(keyParts: Any*)(ttl: Option[Duration])(f: F[V])(implicit flags: Flags): F[V]

Get a value from the cache if it exists. Otherwise compute it, insert it into the cache, and return it.

Get a value from the cache if it exists. Otherwise compute it, insert it into the cache, and return it.

Value Params
f

A block that computes the value wrapped in a container

flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

The cache key

ttl

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

Returns

The value, either retrieved from the cache or computed

def close: F[Unit]

You should call this when you have finished using this Cache. (e.g. when your application shuts down)

You should call this when you have finished using this Cache. (e.g. when your application shuts down)

It will take care of gracefully shutting down the underlying cache client.

Note that you should not try to use this Cache instance after you have called this method.

def get(keyParts: Any*)(implicit flags: Flags): F[Option[V]]

Get a value from the cache

Get a value from the cache

Value Params
flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

The cache key

Returns

The appropriate value, if it was found in the cache

def put(keyParts: Any*)(value: V, ttl: Option[Duration])(implicit flags: Flags): F[Unit]

Insert a value into the cache, optionally setting a TTL (time-to-live)

Insert a value into the cache, optionally setting a TTL (time-to-live)

Value Params
flags

Flags used to conditionally alter the behaviour of ScalaCache

keyParts

The cache key

ttl

The time-to-live. The cache entry will expire after this time has elapsed.

value

The value to insert

def remove(keyParts: Any*): 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.

Value Params
keyParts

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

def removeAll: F[Unit]

Delete the entire contents of the cache. Use wisely!

Delete the entire contents of the cache. Use wisely!