-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suppress Caffeine exceptions: model
Missing
values
We want a way for our `Loading` object to indicate the value for a key is `Missing` (eg we are trying to load an S3 key that does not exist) without having to throw an exception - as Caffeine will noisily log almost every exception it sees, even if the client does not mind missing values, as is the case with the Facia Scala Client. We've introduced the `MissingOrETagged` sealed trait to allow us to represent that a fetch result may be either missing or found, returned with ETagged data. This is an alternative approach to the hacky solution in #32 . Co-authored-by: Jamie B <[email protected]>
- Loading branch information
Showing
7 changed files
with
60 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
core/src/main/scala/com/gu/etagcaching/fetching/ETaggedData.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/src/main/scala/com/gu/etagcaching/fetching/MissingOrETagged.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.gu.etagcaching.fetching | ||
|
||
sealed trait MissingOrETagged[+T] { | ||
def map[S](f: T => S): MissingOrETagged[S] | ||
def toOption: Option[T] | ||
} | ||
|
||
case object Missing extends MissingOrETagged[Nothing] { | ||
override def map[S](f: Nothing => S): MissingOrETagged[S] = Missing | ||
override def toOption: Option[Nothing] = None | ||
} | ||
|
||
/** | ||
* @param eTag https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag | ||
*/ | ||
case class ETaggedData[T](eTag: String, result: T) extends MissingOrETagged[T] { | ||
override def map[S](f: T => S): ETaggedData[S] = copy(result = f(result)) | ||
override def toOption: Option[T] = Some(result) | ||
} |