An abstract implementation of CacheAlg that takes care of some things that are common across all concrete implementations.
Abstract algebra describing the operations a cache can perform
Abstract algebra describing the operations a cache can perform
The value of types stored in the cache.
A cache entry with an optional expiry time
Configuration flags for conditionally altering the behaviour of ScalaCache.
Configuration flags for conditionally altering the behaviour of ScalaCache.
if false, cache GETs will be skipped (and will return None
)
if false, cache PUTs will be skipped
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
Helper methods for logging
When using ScalaCache you must import a mode in order to specify the effect monad in which you want to wrap your computations.
When using ScalaCache you must import a mode in order to specify the effect monad in which you want to wrap your computations.
The effect monad that will wrap the return value of any cache operations. e.g. scalacache.Id, scala.concurrent.Future, scala.util.Try or cats-effect IO.
MD5 returns 32 character long hexadecimal hash strings
SHA1 returns 40 character long hexadecimal hash strings
SHA256 returns 64 character long hexadecimal hash strings
SHA512 returns 128 character long hexadecimal hash strings
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.
Note: Because no TTL is specified, the result will be stored in the cache indefinitely.
The type of container in which the result will be wrapped. This is decided by the mode.
the type of the block's result
Data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.
The time-to-live to use when inserting into the cache. If specified, the cache entry will expire after this time has elapsed.
The block to run
The cache
The operation mode, which decides the type of container in which to wrap the result
Flags used to conditionally alter the behaviour of ScalaCache
The result, either retrived from the cache or returned by the block
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.
Note: Because no TTL is specified, the result will be stored in the cache indefinitely.
The type of container in which the result will be wrapped. This is decided by the mode.
the type of the block's result
Data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.
The time-to-live to use when inserting into the cache. If specified, the cache entry will expire after this time has elapsed.
The block to run
The cache
The operation mode, which decides the type of container in which to wrap the result
Flags used to conditionally alter the behaviour of ScalaCache
The result, either retrived from the cache or returned by the block
Get the value corresponding to the given key from the cache.
Get the value corresponding to the given key from the cache.
The type of container in which the result will be wrapped. This is decided by the mode.
The type of the corresponding value
Data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.
The cache
The operation mode, which decides the type of container in which to wrap the result
Flags used to conditionally alter the behaviour of ScalaCache
the value, if there is one
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.
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.
The type of container in which the result will be wrapped. This is decided by the mode.
The type of the corresponding value
Data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.
the value to be cached
Time To Live (optional, if not specified then the entry will be cached indefinitely)
The cache
The operation mode, which decides the type of container in which to wrap the result
Flags used to conditionally alter the behaviour of ScalaCache
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.
The type of container in which the result will be wrapped. This is decided by the mode.
The type of the value to be removed
Data to be used to generate the cache key. This could be as simple as just a single String. See CacheKeyBuilder.
The cache
The operation mode, which decides the type of container in which to wrap the result
Remove all values from the cache.
Remove all values from the cache.
The type of values to be removed
A version of the API that is specialised to Id.
A version of the API that is specialised to Id. The functions in this API perform their operations immediately on the current thread and thus do not wrap their results in any effect monad.
Implementation note: I really didn't want to have this separate copy of the API, but I couldn't get type inference to understand that Id[A] == A. e.g. the following doesn't compile:
implicit val cache: LovelyCache[String] = ??? import scalacache.modes.sync._ val x: Option[String] = scalacache.get("hello")
[error] ... polymorphic expression cannot be instantiated to expected type; [error] found : [F[_], V]F[Option[V]] [error] required: Option[String]
If anyone can find a workaround to make this compile, I will be much obliged.