Skip to content

Instantly share code, notes, and snippets.

@crypticminds
Created January 13, 2020 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crypticminds/398d6939149a7daf8c1873f41afee1f9 to your computer and use it in GitHub Desktop.
Save crypticminds/398d6939149a7daf8c1873f41afee1f9 to your computer and use it in GitHub Desktop.
import com.arcane.coldstorageannotation.Refrigerate
import java.net.URL
class MakeRemoteCall {
/**
* A method that makes a call to the "https://httpbin.org/get"
* endpoint. This endpoint simply returns the arguments that were passed to it.
* For the caching logic the parameter passed to the endpoint will act as
* the key of the cache.
*
* Since there is only one parameter we don't need to specify the the keys
* field in the annotation.
*/
@Refrigerate(operation = "CallToServiceA", timeToLive = 1000)
fun makeRemoteCallToServiceA(value: String): String {
val url = "https://httpbin.org/get?param1=$value"
val textResponse = URL(url).readText()
return textResponse
}
/**
* We will use the same endpoint but this time we will pass 3 parameters.
* However , out cache key should only be the first 2.
* We can configure the "keys" field in the annotation by specifying
* the variable names that should act as the key of the cache.
* In this case "parameter1" and "parameter2"
*/
@Refrigerate(
operation = "CallToServiceB", timeToLive = 2000,
keys = ["parameter1", "parameter2"]
)
fun makeRemoteCallToServiceB(parameter1: String, parameter2: String, parameter3: String): String {
val url = "https://httpbin.org/get?param1=$parameter1&param2=$parameter2&param3=$parameter3"
val textResponse = URL(url).readText()
return textResponse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment