Search in sources :

Example 1 with Expiry

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);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CacheExpiry(com.adaptris.core.cache.CacheExpiry) Expiry(com.adaptris.core.cache.CacheExpiry.Expiry) ServiceException(com.adaptris.core.ServiceException) UnresolvedMetadataException(com.adaptris.core.UnresolvedMetadataException) Cache(com.adaptris.core.cache.Cache)

Example 2 with Expiry

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);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) CacheExpiry(com.adaptris.core.cache.CacheExpiry) Expiry(com.adaptris.core.cache.CacheExpiry.Expiry)

Aggregations

CacheExpiry (com.adaptris.core.cache.CacheExpiry)2 Expiry (com.adaptris.core.cache.CacheExpiry.Expiry)2 TimeInterval (com.adaptris.util.TimeInterval)2 ServiceException (com.adaptris.core.ServiceException)1 UnresolvedMetadataException (com.adaptris.core.UnresolvedMetadataException)1 Cache (com.adaptris.core.cache.Cache)1