Apache Ignite. Expire policy with using time of last access but no more than max time life
I need to use expired policy with using time last access but no greater max time life. But AccessedExpiryPolicy using the greatest of each time. I.e:
Part of my configuration:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="expiredAccessCache"/>
<property name="cacheMode" value="REPLICATED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="expiryPolicyFactory">
<bean class="com.stackoverflow.question53944630.MyExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="10"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
MyExpiryPolicy.java
consisting of different policies for last access time and creation time:
package com.stackoverflow.question53944630;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import java.io.Serializable;
import java.util.Objects;
public class MyExpiryPolicy implements ExpiryPolicy, Serializable {
private Duration expiryDurationAccess;
private Duration expiryDurationCreate;
public MyExpiryPolicy(Duration expiryDurationCreate, Duration expiryDurationAccess) {
this.expiryDurationCreate = expiryDurationCreate;
this.expiryDurationAccess = expiryDurationAccess;
}
public static Factory<ExpiryPolicy> factoryOf(Duration expiryDurationCreate, Duration expiryDurationAccess) {
return new FactoryBuilder.SingletonFactory<>(new MyExpiryPolicy(expiryDurationCreate, expiryDurationAccess));
}
@Override
public Duration getExpiryForCreation() {
return expiryDurationCreate;
}
@Override
public Duration getExpiryForAccess() {
return expiryDurationAccess;
}
@Override
public Duration getExpiryForUpdate() {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyExpiryPolicy that = (MyExpiryPolicy) o;
return Objects.equals(expiryDurationAccess, that.expiryDurationAccess) &&
Objects.equals(expiryDurationCreate, that.expiryDurationCreate);
}
@Override
public int hashCode() {
return Objects.hash(expiryDurationAccess, expiryDurationCreate);
}
}
Test:
@Test
void testExpirePolicy() throws Exception {
IgniteCache<String, String> cache = ignite.cache("expiredAccessCache");
String key = "key";
String val = "value";
cache.put(key, val);
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
//12 seconds (>10 seconds in config) after creation and 4 (<5 seconds in configuration) after last access
Assertions.assertNull(cache.get(key)); //error, value is not null, but i need to get null
}
I want than last test condition is passed, but I get an error.
How to implement it?
caching ignite
add a comment |
I need to use expired policy with using time last access but no greater max time life. But AccessedExpiryPolicy using the greatest of each time. I.e:
Part of my configuration:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="expiredAccessCache"/>
<property name="cacheMode" value="REPLICATED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="expiryPolicyFactory">
<bean class="com.stackoverflow.question53944630.MyExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="10"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
MyExpiryPolicy.java
consisting of different policies for last access time and creation time:
package com.stackoverflow.question53944630;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import java.io.Serializable;
import java.util.Objects;
public class MyExpiryPolicy implements ExpiryPolicy, Serializable {
private Duration expiryDurationAccess;
private Duration expiryDurationCreate;
public MyExpiryPolicy(Duration expiryDurationCreate, Duration expiryDurationAccess) {
this.expiryDurationCreate = expiryDurationCreate;
this.expiryDurationAccess = expiryDurationAccess;
}
public static Factory<ExpiryPolicy> factoryOf(Duration expiryDurationCreate, Duration expiryDurationAccess) {
return new FactoryBuilder.SingletonFactory<>(new MyExpiryPolicy(expiryDurationCreate, expiryDurationAccess));
}
@Override
public Duration getExpiryForCreation() {
return expiryDurationCreate;
}
@Override
public Duration getExpiryForAccess() {
return expiryDurationAccess;
}
@Override
public Duration getExpiryForUpdate() {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyExpiryPolicy that = (MyExpiryPolicy) o;
return Objects.equals(expiryDurationAccess, that.expiryDurationAccess) &&
Objects.equals(expiryDurationCreate, that.expiryDurationCreate);
}
@Override
public int hashCode() {
return Objects.hash(expiryDurationAccess, expiryDurationCreate);
}
}
Test:
@Test
void testExpirePolicy() throws Exception {
IgniteCache<String, String> cache = ignite.cache("expiredAccessCache");
String key = "key";
String val = "value";
cache.put(key, val);
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
//12 seconds (>10 seconds in config) after creation and 4 (<5 seconds in configuration) after last access
Assertions.assertNull(cache.get(key)); //error, value is not null, but i need to get null
}
I want than last test condition is passed, but I get an error.
How to implement it?
caching ignite
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
@alamar, i edited question
– Темка тоже
yesterday
Isn't itCreatedExpiryPolicy
?
– alamar
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday
add a comment |
I need to use expired policy with using time last access but no greater max time life. But AccessedExpiryPolicy using the greatest of each time. I.e:
Part of my configuration:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="expiredAccessCache"/>
<property name="cacheMode" value="REPLICATED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="expiryPolicyFactory">
<bean class="com.stackoverflow.question53944630.MyExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="10"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
MyExpiryPolicy.java
consisting of different policies for last access time and creation time:
package com.stackoverflow.question53944630;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import java.io.Serializable;
import java.util.Objects;
public class MyExpiryPolicy implements ExpiryPolicy, Serializable {
private Duration expiryDurationAccess;
private Duration expiryDurationCreate;
public MyExpiryPolicy(Duration expiryDurationCreate, Duration expiryDurationAccess) {
this.expiryDurationCreate = expiryDurationCreate;
this.expiryDurationAccess = expiryDurationAccess;
}
public static Factory<ExpiryPolicy> factoryOf(Duration expiryDurationCreate, Duration expiryDurationAccess) {
return new FactoryBuilder.SingletonFactory<>(new MyExpiryPolicy(expiryDurationCreate, expiryDurationAccess));
}
@Override
public Duration getExpiryForCreation() {
return expiryDurationCreate;
}
@Override
public Duration getExpiryForAccess() {
return expiryDurationAccess;
}
@Override
public Duration getExpiryForUpdate() {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyExpiryPolicy that = (MyExpiryPolicy) o;
return Objects.equals(expiryDurationAccess, that.expiryDurationAccess) &&
Objects.equals(expiryDurationCreate, that.expiryDurationCreate);
}
@Override
public int hashCode() {
return Objects.hash(expiryDurationAccess, expiryDurationCreate);
}
}
Test:
@Test
void testExpirePolicy() throws Exception {
IgniteCache<String, String> cache = ignite.cache("expiredAccessCache");
String key = "key";
String val = "value";
cache.put(key, val);
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
//12 seconds (>10 seconds in config) after creation and 4 (<5 seconds in configuration) after last access
Assertions.assertNull(cache.get(key)); //error, value is not null, but i need to get null
}
I want than last test condition is passed, but I get an error.
How to implement it?
caching ignite
I need to use expired policy with using time last access but no greater max time life. But AccessedExpiryPolicy using the greatest of each time. I.e:
Part of my configuration:
<bean class="org.apache.ignite.configuration.CacheConfiguration">
<property name="name" value="expiredAccessCache"/>
<property name="cacheMode" value="REPLICATED"/>
<property name="atomicityMode" value="TRANSACTIONAL"/>
<property name="writeSynchronizationMode" value="FULL_SYNC"/>
<property name="expiryPolicyFactory">
<bean class="com.stackoverflow.question53944630.MyExpiryPolicy" factory-method="factoryOf">
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="10"/>
</bean>
</constructor-arg>
<constructor-arg>
<bean class="javax.cache.expiry.Duration">
<constructor-arg value="SECONDS"/>
<constructor-arg value="5"/>
</bean>
</constructor-arg>
</bean>
</property>
</bean>
MyExpiryPolicy.java
consisting of different policies for last access time and creation time:
package com.stackoverflow.question53944630;
import javax.cache.configuration.Factory;
import javax.cache.configuration.FactoryBuilder;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import java.io.Serializable;
import java.util.Objects;
public class MyExpiryPolicy implements ExpiryPolicy, Serializable {
private Duration expiryDurationAccess;
private Duration expiryDurationCreate;
public MyExpiryPolicy(Duration expiryDurationCreate, Duration expiryDurationAccess) {
this.expiryDurationCreate = expiryDurationCreate;
this.expiryDurationAccess = expiryDurationAccess;
}
public static Factory<ExpiryPolicy> factoryOf(Duration expiryDurationCreate, Duration expiryDurationAccess) {
return new FactoryBuilder.SingletonFactory<>(new MyExpiryPolicy(expiryDurationCreate, expiryDurationAccess));
}
@Override
public Duration getExpiryForCreation() {
return expiryDurationCreate;
}
@Override
public Duration getExpiryForAccess() {
return expiryDurationAccess;
}
@Override
public Duration getExpiryForUpdate() {
return null;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MyExpiryPolicy that = (MyExpiryPolicy) o;
return Objects.equals(expiryDurationAccess, that.expiryDurationAccess) &&
Objects.equals(expiryDurationCreate, that.expiryDurationCreate);
}
@Override
public int hashCode() {
return Objects.hash(expiryDurationAccess, expiryDurationCreate);
}
}
Test:
@Test
void testExpirePolicy() throws Exception {
IgniteCache<String, String> cache = ignite.cache("expiredAccessCache");
String key = "key";
String val = "value";
cache.put(key, val);
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
Assertions.assertNotNull(cache.get(key));
Thread.sleep(4000);
//12 seconds (>10 seconds in config) after creation and 4 (<5 seconds in configuration) after last access
Assertions.assertNull(cache.get(key)); //error, value is not null, but i need to get null
}
I want than last test condition is passed, but I get an error.
How to implement it?
caching ignite
caching ignite
edited yesterday
asked yesterday
Темка тоже
18518
18518
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
@alamar, i edited question
– Темка тоже
yesterday
Isn't itCreatedExpiryPolicy
?
– alamar
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday
add a comment |
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
@alamar, i edited question
– Темка тоже
yesterday
Isn't itCreatedExpiryPolicy
?
– alamar
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
@alamar, i edited question
– Темка тоже
yesterday
@alamar, i edited question
– Темка тоже
yesterday
Isn't it
CreatedExpiryPolicy
?– alamar
yesterday
Isn't it
CreatedExpiryPolicy
?– alamar
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday
add a comment |
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53944630%2fapache-ignite-expire-policy-with-using-time-of-last-access-but-no-more-than-max%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53944630%2fapache-ignite-expire-policy-with-using-time-of-last-access-but-no-more-than-max%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
"with using last using time but no greater max time life" can you elaborate? Presently it's not clear what you are trying to do.
– alamar
yesterday
@alamar, i edited question
– Темка тоже
yesterday
Isn't it
CreatedExpiryPolicy
?– alamar
yesterday
@alamar I added more details and MyExpiryPolicy for clarification.
– Темка тоже
yesterday