gfc-cache
![Coverage Status](https://camo.githubusercontent.com/3973d95d2a8ba1268ad7d289ba657bb45a0b22e9b1bd2c7bd6c06a8c059dea30/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6766632d636f6c6c6563746976652f6766632d63616368652f62616467652e7376673f6272616e63683d6d61696e26736572766963653d676974687562)
A library that contains scala caching helper code. A fork and new home of the now unmaintained Gilt Foundation Classes (com.gilt.gfc
), now called the GFC Collective, maintained by some of the original authors.
Getting gfc-cache
The latest version is 1.0.0, released on 21/Jan/2020 and cross-built against Scala 2.12.x and 2.13.x.
If you're using SBT, add the following line to your build file:
libraryDependencies += "org.gfccollective" %% "gfc-cache" % "1.0.0"
For Maven and other build tools, you can visit search.maven.org. (This search will also list other available libraries from the GFC Collective.)
Contents and Example Usage
org.gfccollective.cache.AsyncCache & AsyncCacheImpl
AsyncCache
represents an asynchronous cache. It may not contain the whole data, and will return Future[Option[V]]
to show that the value may be lazy-loaded by issuing a remote call.
AsyncCacheImpl
is an implementation of AsyncCache
that adds build-load functionality, which requires a load function to be implemented, which is called on cache-miss.
org.gfccollective.cache.SyncCache & SyncCacheImpl
SyncCache
represents an in-memory cache, returning values as Option[V]
indicating that no values are lazy-loaded on cache-miss.
SyncCacheImpl
is an implementation of SyncCache
that adds build-load functionality, which requires a load function to be implemented, which is called on cache-miss.
org.gfccollective.cache.CacheConfiguration
Mix in this trait to provide configuration for the cache. The following parameters are needed:
refreshPeriodMs
: how often to reload the cache, in millis.cacheInitStrategy
: how to initialize the cache, either synchronously or asynchronously.
Code coverage report
$ sbt clean coverage test coverageReport
License
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0