use of com.adaptris.core.cache.CacheExpiry.Expiry in project interlok by adaptris.
the class AddValueToCache method doService.
@Override
public void doService(AdaptrisMessage msg) throws ServiceException {
try {
Cache cache = retrieveCache();
Optional<Expiry> hasExpiry = buildExpiry(msg);
String cacheKey = msg.resolve(getKey());
// should be hasExpiry.ifPresentOrElse() once we goto J11...
if (hasExpiry.isPresent()) {
TimeInterval expiryInterval = hasExpiry.get().expiresIn();
log.trace("[{}] will expire in {}", cacheKey, expiryInterval);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg), hasExpiry.get().expiresIn());
} else {
log.trace("Expiry for [{}] taken from cache settings", cacheKey);
cache.put(cacheKey, getValueTranslator().getValueFromMessage(msg));
}
} catch (Exception e) {
throw ExceptionHelper.wrapServiceException(e);
}
}
use of com.adaptris.core.cache.CacheExpiry.Expiry in project interlok by adaptris.
the class GetAndCacheOauthToken method addToCache.
private void addToCache(Cache cache, String key, AccessToken token) throws Exception {
Optional<Expiry> hasExpiry = CacheExpiry.buildExpiry(token.getExpiry());
// should be hasExpiry.ifPresentOrElse() once we goto J11...
if (hasExpiry.isPresent()) {
TimeInterval expiryInterval = hasExpiry.get().expiresIn();
log.trace("[{}] will expire in {}", key, expiryInterval);
cache.put(key, token, hasExpiry.get().expiresIn());
} else {
log.trace("Expiry for [{}] taken from cache settings", key);
cache.put(key, token);
}
}
Aggregations