You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Ariel Tubaltsev <tu...@gmail.com> on 2018/01/22 23:51:22 UTC

Key Value Store - control TTL refresh

I'd like to set TTL for all entries in some map.

Along with that I'd like to control operations that refresh TTL. For
instance simple Read/Write should update the TTL, but pulling the whole map
should not.

Is that something that can be done with current expiry policies?

https://apacheignite.readme.io/docs/expiry-policies



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

RE: Key Value Store - control TTL refresh

Posted by Ariel Tubaltsev <tu...@gmail.com>.
Hi Stan

That makes sense to me. Thank you for explanation.

Ariel



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

RE: Key Value Store - control TTL refresh

Posted by Stanislav Lukyanov <st...@gmail.com>.
Hi,

Whenever an entry is touched, the expiry policy of the view that was used
for that will be consulted to get a new TTL. It means that each time you
touch an entry through a view with `EternalExpiryPolicy` its TTL will be
reset to ETERNAL. You could say that the `bypassCache` from your example
should actually be called `keepAliveCache` or something like that.

If you don't want your operations to have an effect on the TTL, you should
use the original cache without an expiry policy set. If you want to build a
"bypass expiry policy" (for the sake of uniformness or just for fun) you can
try creating an `ExpiryPolicy` that returns `null` for access and
modification and `ETERNAL` for creation - I believe that should have the
same effect as having no `ExpiryPolicy` at all.

Stan


Ariel Tubaltsev wrote
> Hi Stan
> 
> Thank you for the quick reply.
> 
> Let me clarify my use case: I want to have expiration for all regular
> operations.
> Along with that, I want to be able to read some or all entries without
> refreshing TTLs, for example for debugging.
> 
> Following your example, I create a view with expiration and a view without
> it, my understanding is that accessing through the view with
> EternalExpiryPolicy shouldn't refresh TTLs - which seems to work.
> 
> However, accessing through the view with  TouchedExpiryPolicy doesn't seem
> to refresh TTLs.
> 
> Do you think something like that should work?
> 
>           // Auto-close cache at the end of the example.
>             try (IgniteCache&lt;String, String&gt; cache =
> ignite.getOrCreateCache(CACHE_NAME)) {
> 
>                 // create not expiring view
>                 IgniteCache&lt;String, String&gt; bypassCache =
> cache.withExpiryPolicy(new EternalExpiryPolicy());
> 
>                 // create expiring view, 10 seconds TTL
>                 System.out.println(">>> Set entries to expire in 10
> seconds");
>                 IgniteCache&lt;String, String&gt; workCache =
> cache.withExpiryPolicy(new TouchedExpiryPolicy(new
> Duration(TimeUnit.SECONDS, 10)));
> 
>                 // entries shouldn't survive
>                 populate(workCache);
>                 sleep(5); // sleep for 5 seconds
>                 System.out.println("\n>>> Dump cache, don't refresh TTL");
>                 getAll(bypassCache);
>                 sleep(5);
>                 System.out.println("\n>>> Work cache should be empty");
>                 getAll(workCache);
>                 System.out.println("\n>>> Bypass cache should be empty");
>                 getAll(bypassCache);
> 
>                 // entries should survive
>                 populate(workCache);
>                 sleep(5);
>                 System.out.println("\n>>> Dump cache, refresh TTL"); //
> entries are still there
>                 getAll(workCache);
>                 sleep(5);
>                 System.out.println("\n>>> Bypass cache should be not
> empty"); // entries are gone
>                 getAll(bypassCache);
>                 System.out.println("\n>>> Work cache should be not
> empty");
>                 getAll(workCache);
> 
> ...
> 
> Ariel
> 
> 
> 
> 
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/





--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

RE: Key Value Store - control TTL refresh

Posted by Ariel Tubaltsev <tu...@gmail.com>.
Hi Stan

Thank you for the quick reply.

Let me clarify my use case: I want to have expiration for all regular
operations.
Along with that, I want to be able to read some or all entries without
refreshing TTLs, for example for debugging.

Following your example, I create a view with expiration and a view without
it, my understanding is that accessing through the view with
EternalExpiryPolicy shouldn't refresh TTLs - which seems to work.

However, accessing through the view with  TouchedExpiryPolicy doesn't seem
to refresh TTLs.

Do you think something like that should work?

          // Auto-close cache at the end of the example.
            try (IgniteCache<String, String> cache =
ignite.getOrCreateCache(CACHE_NAME)) {

                // create not expiring view
                IgniteCache<String, String> bypassCache =
cache.withExpiryPolicy(new EternalExpiryPolicy());

                // create expiring view, 10 seconds TTL
                System.out.println(">>> Set entries to expire in 10
seconds");
                IgniteCache<String, String> workCache =
cache.withExpiryPolicy(new TouchedExpiryPolicy(new
Duration(TimeUnit.SECONDS, 10)));

                // entries shouldn't survive
                populate(workCache);
                sleep(5); // sleep for 5 seconds
                System.out.println("\n>>> Dump cache, don't refresh TTL");
                getAll(bypassCache);
                sleep(5);
                System.out.println("\n>>> Work cache should be empty");
                getAll(workCache);
                System.out.println("\n>>> Bypass cache should be empty");
                getAll(bypassCache);

                // entries should survive
                populate(workCache);
                sleep(5);
                System.out.println("\n>>> Dump cache, refresh TTL"); //
entries are still there
                getAll(workCache);
                sleep(5);
                System.out.println("\n>>> Bypass cache should be not
empty"); // entries are gone
                getAll(bypassCache);
                System.out.println("\n>>> Work cache should be not empty");
                getAll(workCache);

...

Ariel




--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

RE: Key Value Store - control TTL refresh

Posted by Stanislav Lukyanov <st...@gmail.com>.
Hi,

Ignite uses JCache’s ExpiryPolicy, and that API only provides a way to specify three kinds of TTL – for creation, modification and access.
AFAIU you’d like to tune TTL on a finer level, having different values per different operations. If so, you can’t do that just with ExpiryPolicy.
But you can create several views of a cache with IgniteCache::withExpiryPolicy, and use them to perform operations with different effect on the TTL.

        try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
            IgniteCache<String, String> cache = ignite.getOrCreateCache("MyCache");

            IgniteCache<String, String> eternalCache = cache.withExpiryPolicy(new EternalExpiryPolicy());
            IgniteCache<String, String> temporaryCache = cache.withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 10)));

            eternalCache.put("eternal", "foo");
            temporaryCache.put("temp", "bar");

            System.out.println("Before sleep:");
            System.out.println(cache.get("eternal"));
            System.out.println(cache.get("temp"));

            Thread.sleep(10_000);

            System.out.println("After sleep:");
            System.out.println(cache.get("eternal"));
            System.out.println(cache.get("temp"));
        }

Output of that is:
    Before sleep:
    foo
    bar
    After sleep:
    foo
    null

Stan

From: Ariel Tubaltsev
Sent: 23 января 2018 г. 2:51
To: user@ignite.apache.org
Subject: Key Value Store - control TTL refresh

I'd like to set TTL for all entries in some map.

Along with that I'd like to control operations that refresh TTL. For
instance simple Read/Write should update the TTL, but pulling the whole map
should not.

Is that something that can be done with current expiry policies?

https://apacheignite.readme.io/docs/expiry-policies



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/