Created
February 9, 2018 22:23
-
-
Save bandrzejczak/115990ebc460982bf9fda544cb1c4f55 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def cachingWithTTL[T, M[_]](keyParts: Any*)(value: => M[(T, Duration)]) | |
(implicit cache: Cache[T], mode: Mode[M], flags: Flags): M[T] = { | |
import mode._ | |
M.flatMap(get(keyParts:_*)) { | |
case Some(found) => M.pure(found) | |
case None => | |
M.flatMap(value) { | |
case (v, ttl) => | |
M.map(put(keyParts:_*)(v, Some(ttl)))(_ => v) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment