use of javax.cache.expiry.ExpiryPolicy in project cas by apereo.
the class IgniteTicketRegistry method addTicket.
@Override
public void addTicket(final Ticket ticketToAdd) {
final Ticket ticket = encodeTicket(ticketToAdd);
LOGGER.debug("Adding ticket [{}] to the cache [{}]", ticket.getId(), this.ticketIgniteCache.getName());
this.ticketIgniteCache.withExpiryPolicy(new ExpiryPolicy() {
@Override
public Duration getExpiryForCreation() {
return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
}
@Override
public Duration getExpiryForAccess() {
final long idleTime = ticket.getExpirationPolicy().getTimeToIdle() <= 0 ? ticket.getExpirationPolicy().getTimeToLive() : ticket.getExpirationPolicy().getTimeToIdle();
return new Duration(TimeUnit.SECONDS, idleTime);
}
@Override
public Duration getExpiryForUpdate() {
return new Duration(TimeUnit.SECONDS, ticket.getExpirationPolicy().getTimeToLive());
}
}).put(ticket.getId(), ticket);
}
use of javax.cache.expiry.ExpiryPolicy in project hazelcast by hazelcast.
the class CacheGetAllMessageTask method createOperationFactory.
@Override
protected OperationFactory createOperationFactory() {
CacheOperationProvider operationProvider = getOperationProvider(parameters.name);
CacheService service = getService(getServiceName());
ExpiryPolicy expiryPolicy = (ExpiryPolicy) service.toObject(parameters.expiryPolicy);
Set<Data> keys = new HashSet<Data>(parameters.keys);
return operationProvider.createGetAllOperationFactory(keys, expiryPolicy);
}
use of javax.cache.expiry.ExpiryPolicy in project hazelcast by hazelcast.
the class CacheGetAndReplaceMessageTask method prepareOperation.
@Override
protected Operation prepareOperation() {
CacheOperationProvider operationProvider = getOperationProvider(parameters.name);
ExpiryPolicy expiryPolicy = (ExpiryPolicy) nodeEngine.toObject(parameters.expiryPolicy);
return operationProvider.createGetAndReplaceOperation(parameters.key, parameters.value, expiryPolicy, parameters.completionId);
}
use of javax.cache.expiry.ExpiryPolicy in project hazelcast by hazelcast.
the class CachePutIfAbsentMessageTask method prepareOperation.
@Override
protected Operation prepareOperation() {
CacheOperationProvider operationProvider = getOperationProvider(parameters.name);
ExpiryPolicy expiryPolicy = (ExpiryPolicy) nodeEngine.toObject(parameters.expiryPolicy);
return operationProvider.createPutIfAbsentOperation(parameters.key, parameters.value, expiryPolicy, parameters.completionId);
}
use of javax.cache.expiry.ExpiryPolicy in project hazelcast by hazelcast.
the class CachePutAllTest method testPutAllWithExpiration.
@Test
public void testPutAllWithExpiration() {
final long EXPIRATION_TIME_IN_MILLISECONDS = 5000;
ExpiryPolicy expiryPolicy = new HazelcastExpiryPolicy(EXPIRATION_TIME_IN_MILLISECONDS, 0, 0);
ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
cache.putAll(entries, expiryPolicy);
sleepAtLeastMillis(EXPIRATION_TIME_IN_MILLISECONDS + 1000);
// Verify that expiration of put-all works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String actualValue = cache.get(key);
assertNull(actualValue);
}
}
Aggregations