in facia-json/src/main/scala/com/gu/facia/client/ApiClient.scala [58:81]
def withCaching(
bucket: String,
environment: Environment,
s3Fetching: S3ByteArrayFetching,
configureCollectionCache: ConfigCache = _.maximumSize(10000) // at most 1GB RAM worst case
)(implicit ec: ExecutionContext): ApiClient = new ApiClient {
private val fetching =
s3Fetching.keyOn[String](path => ObjectId(bucket, path))
def eTagCache[B: Format](configureCache: ConfigCache) = new ETagCache(
fetching.thenParsing(parseBytes[B]),
AlwaysWaitForRefreshedValue,
configureCache
)
private val configCache = eTagCache[ConfigJson](_.maximumSize(1))
private val collectionCache = eTagCache[CollectionJson](configureCollectionCache)
override def config: Future[ConfigJson] =
configCache.get(environment.configS3Path).map(getOrWarnAboutMissingConfig)
override def collection(id: String): Future[Option[CollectionJson]] =
collectionCache.get(environment.collectionS3Path(id))
}