The Cache URL Environment Variable
To access a cache service, your application must be able to read the CACHING_INTERNAL_CACHE_URL
environment variable at runtime.
This variable contains effectively the hostname of the cache service. Your application uses this variable to construct the URL for communicating with the cache service.
The REST API for caching applications uses port 8080
.
Example 3-1 Reading the Environment Variable in a Java Application
public static final String CACHEHOST;
public static final String CACHEPORT = "8080";
public static final String CACHEURL;
static {
CACHEHOST = System.getenv("CACHING_INTERNAL_CACHE_URL");
if (CACHEHOST == null){
System.out.println("CACHING_INTERNAL_CACHE_URL not set");
System.exit(0);
}
CACHEURL = "http://" + CACHEHOST + ":" + CACHEPORT + "/ccs/";
}
Example 3-2 Reading the Environment Variable in a Node.js Application
process.on('exit', (code) => {
console.log('CACHING_INTERNAL_CACHE_URL not set: ${code}');
});
var CCSHOST = process.env.CACHING_INTERNAL_CACHE_URL || process.exit(0);
var baseCCSURL = 'http://' + CCSHOST + ':8080/ccs/';
Example 3-3 Reading the Environment variable in a PHP Application
$cacheService = getenv('CACHING_INTERNAL_CACHE_URL') ? getenv('CACHING_INTERNAL_CACHE_URL') : '';
if(strlen($cacheService) == 0)
{
throw new Exception('No cache service found', 500);
}
$base_url = 'http://'.$cacheService.':8080/ccs/'