Search in sources :

Example 1 with ExpiryPolicy

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);
}
Also used : Ticket(org.apereo.cas.ticket.Ticket) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Duration(javax.cache.expiry.Duration)

Example 2 with ExpiryPolicy

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);
}
Also used : CacheOperationProvider(com.hazelcast.cache.impl.CacheOperationProvider) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Data(com.hazelcast.nio.serialization.Data) CacheService(com.hazelcast.cache.impl.CacheService) HashSet(java.util.HashSet)

Example 3 with 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);
}
Also used : CacheOperationProvider(com.hazelcast.cache.impl.CacheOperationProvider) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy)

Example 4 with ExpiryPolicy

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);
}
Also used : CacheOperationProvider(com.hazelcast.cache.impl.CacheOperationProvider) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy)

Example 5 with ExpiryPolicy

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);
    }
}
Also used : ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) HashMap(java.util.HashMap) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ExpiryPolicy (javax.cache.expiry.ExpiryPolicy)54 Duration (javax.cache.expiry.Duration)24 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)15 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)12 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)11 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)11 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)10 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)9 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)9 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)9 CacheOperationProvider (com.hazelcast.cache.impl.CacheOperationProvider)7 UUID (java.util.UUID)7 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 Transaction (org.apache.ignite.transactions.Transaction)7 Map (java.util.Map)5 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)5 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)5 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)5