use of javax.cache.expiry.Duration in project caffeine by ben-manes.
the class JCacheLoaderAdapter method expireTimeMS.
private long expireTimeMS() {
try {
Duration duration = expiry.getExpiryForCreation();
if (duration.isZero()) {
return 0;
} else if (duration.isEternal()) {
return Long.MAX_VALUE;
}
long millis = TimeUnit.NANOSECONDS.toMillis(ticker.read());
return duration.getAdjustedTime(millis);
} catch (Exception e) {
return Long.MAX_VALUE;
}
}
use of javax.cache.expiry.Duration in project caffeine by ben-manes.
the class CacheProxy method setAccessExpirationTime.
/**
* Sets the access expiration time.
*
* @param expirable the entry that was operated on
* @param currentTimeMS the current time, or 0 if not read yet
*/
protected final void setAccessExpirationTime(Expirable<?> expirable, long currentTimeMS) {
try {
Duration duration = expiry.getExpiryForAccess();
if (duration == null) {
return;
} else if (duration.isZero()) {
expirable.setExpireTimeMS(0L);
} else if (duration.isEternal()) {
expirable.setExpireTimeMS(Long.MAX_VALUE);
} else {
if (currentTimeMS == 0) {
currentTimeMS = ticker.read();
}
long expireTimeMS = duration.getAdjustedTime(currentTimeMS);
expirable.setExpireTimeMS(expireTimeMS);
}
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to set the entry's expiration time", e);
}
}
use of javax.cache.expiry.Duration in project hazelcast by hazelcast.
the class AbstractCacheRecordStore method createRecordWithExpiry.
protected R createRecordWithExpiry(Data key, Object value, ExpiryPolicy expiryPolicy, long now, boolean disableWriteThrough, int completionId, String origin) {
expiryPolicy = getExpiryPolicy(expiryPolicy);
Duration expiryDuration;
try {
expiryDuration = expiryPolicy.getExpiryForCreation();
} catch (Exception e) {
expiryDuration = Duration.ETERNAL;
}
long expiryTime = getAdjustedExpireTime(expiryDuration, now);
return createRecordWithExpiry(key, value, expiryTime, now, disableWriteThrough, completionId, origin);
}
use of javax.cache.expiry.Duration in project caffeine by ben-manes.
the class JCacheAccessExpiryTest method getConfiguration.
@Override
protected CaffeineConfiguration<Integer, Integer> getConfiguration() {
CaffeineConfiguration<Integer, Integer> configuration = new CaffeineConfiguration<>();
configuration.setExpiryPolicyFactory(() -> new AccessedExpiryPolicy(new Duration(TimeUnit.MILLISECONDS, EXPIRY_DURATION)));
configuration.setTickerFactory(() -> ticker::read);
return configuration;
}
use of javax.cache.expiry.Duration in project camel by apache.
the class IgniteEventsTest method testConsumeAllEvents.
@Test
public void testConsumeAllEvents() throws Exception {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("ignite:events:abc").to("mock:test1");
}
});
getMockEndpoint("mock:test1").expectedMinimumMessageCount(9);
IgniteCache<String, String> cache = ignite().getOrCreateCache("abc");
// Generate cache activity.
cache.put("abc", "123");
cache.get("abc");
cache.remove("abc");
cache.withExpiryPolicy(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, 100)).create()).put("abc", "123");
Thread.sleep(150);
cache.get("abc");
assertMockEndpointsSatisfied();
List<Integer> eventTypes = receivedEventTypes("mock:test1");
assert_().that(eventTypes).containsAllOf(EventType.EVT_CACHE_STARTED, EventType.EVT_CACHE_ENTRY_CREATED, EventType.EVT_CACHE_OBJECT_PUT, EventType.EVT_CACHE_OBJECT_READ, EventType.EVT_CACHE_OBJECT_REMOVED, EventType.EVT_CACHE_OBJECT_PUT, EventType.EVT_CACHE_OBJECT_EXPIRED).inOrder();
}
Aggregations