use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method updateAccessDuration.
protected long updateAccessDuration(Data key, R record, ExpiryPolicy expiryPolicy, long now) {
long expiryTime = TIME_NOT_AVAILABLE;
try {
Duration expiryDuration = expiryPolicy.getExpiryForAccess();
if (expiryDuration != null) {
expiryTime = getAdjustedExpireTime(expiryDuration, now);
record.setExpirationTime(expiryTime);
if (isEventsEnabled()) {
CacheEventContext cacheEventContext = createBaseEventContext(CacheEventType.EXPIRATION_TIME_UPDATED, toEventData(key), toEventData(record.getValue()), expiryTime, null, IGNORE_COMPLETION);
cacheEventContext.setAccessHit(record.getHits());
publishEvent(cacheEventContext);
}
}
} catch (Exception e) {
ignore(e);
}
return expiryTime;
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method updateRecordWithExpiry.
@SuppressWarnings("checkstyle:parameternumber")
protected boolean updateRecordWithExpiry(Data key, Object value, R record, ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, UUID source, UUID origin) {
expiryPolicy = getExpiryPolicy(record, expiryPolicy);
long expiryTime = TIME_NOT_AVAILABLE;
try {
Duration expiryDuration = expiryPolicy.getExpiryForUpdate();
if (expiryDuration != null) {
expiryTime = getAdjustedExpireTime(expiryDuration, now);
}
} catch (Exception e) {
ignore(e);
}
return updateRecordWithExpiry(key, value, record, expiryTime, now, disableWriteThrough, completionId, source, origin);
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheExpirationTest method test_whenEntryIsRemovedBackupIsCleaned.
@Test
public void test_whenEntryIsRemovedBackupIsCleaned() {
int ttlSeconds = 3;
Duration duration = new Duration(TimeUnit.SECONDS, ttlSeconds);
HazelcastExpiryPolicy expiryPolicy = new HazelcastExpiryPolicy(duration, duration, duration);
CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(expiryPolicy);
Cache<Integer, Integer> cache = createCache(cacheConfig);
for (int i = 0; i < KEY_RANGE; i++) {
cache.put(i, i);
}
for (int i = 0; i < KEY_RANGE; i++) {
cache.remove(i, i);
}
for (int i = 1; i < CLUSTER_SIZE; i++) {
BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
assertBackupSizeEventually(0, backupAccessor);
}
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method expiryTimeShouldNotBeChangedOnUpdateWhenCreatedExpiryPolicyIsUsed.
// https://github.com/hazelcast/hazelcast/issues/7236
@Test
public void expiryTimeShouldNotBeChangedOnUpdateWhenCreatedExpiryPolicyIsUsed() {
final int createdExpiryTimeMillis = 100;
Duration duration = new Duration(TimeUnit.MILLISECONDS, createdExpiryTimeMillis);
CacheConfig<Integer, String> cacheConfig = new CacheConfig<>();
cacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(duration));
Cache<Integer, String> cache = createCache(cacheConfig);
cache.put(1, "value");
cache.put(1, "value");
sleepAtLeastMillis(createdExpiryTimeMillis + 1);
assertNull(cache.get(1));
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class CacheBasicAbstractTest method testRecordExpiryPolicyTakesPrecedenceOverPolicyAtCreation.
@Test
public void testRecordExpiryPolicyTakesPrecedenceOverPolicyAtCreation() {
final int updatedTtlMillis = 1000;
ICache<Integer, String> cache = createCache();
cache.put(1, "value", new TouchedExpiryPolicy(Duration.ONE_DAY));
cache.setExpiryPolicy(1, new TouchedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, updatedTtlMillis)));
sleepAtLeastMillis(updatedTtlMillis + 1);
assertNull(cache.get(1));
}
Aggregations