set ExpiryPolicy does not work in C# client code

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

set ExpiryPolicy does not work in C# client code

右边口袋
Guys,

    I test below code and found the key(key1) still exists after 100 milliseconds(even longer), seems cache.WithExpiryPolicy does not work?

    Can someone tell how to set ExpiryPolicy in config.xml? Thanks much!

    Code snippet:
    public static void WriteTestCache(IIgnite ignite)
        {
            try
            {
                cache = ignite.GetOrCreateCache<string, string>("cache_test");
                cache.WithExpiryPolicy(new ExpiryPolicy(TimeSpan.FromMilliseconds(100),
                TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(100)));

                cache.Put("key1", "value1");
            }
            catch (Exception ex)
            {
                Console.WriteLine("IgniteHttpTest:WriteTestCache, ex {0}", ex);
            }
        }
Reply | Threaded
Open this post in threaded view
|

Re: set ExpiryPolicy does not work in C# client code

Valentin Kulichenko
WithExpiryPolicy() returns another instance of ICache with overridden
expiry policy and you should use this new instance to do the Put. So the
code should look like this:

cache.WithExpiryPolicy(new ExpiryPolicy(TimeSpan.FromMilliseconds(100),
TimeSpan.FromMilliseconds(100),
    TimeSpan.FromMilliseconds(100))).Put("key1", "value1");

In the XML configuration you can specify the expiry policy like this:

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <property name="expiryPolicyFactory">
        <bean
class="javax.cache.configuration.FactoryBuilder$SingletonFactory">
            <constructor-arg>
                <bean class="javax.cache.expiry.TouchedExpiryPolicy">
                    <constructor-arg>
                        <bean class="javax.cache.expiry.Duration">
                            <constructor-arg
type="java.util.concurrent.TimeUnit" value="MILLISECONDS"/>
                            <constructor-arg type="long" value="100"/>
                        </bean>
                    </constructor-arg>
                </bean>
            </constructor-arg>
        </bean>
    </property>
</bean>

-Val

On Tue, Jul 12, 2016 at 5:50 AM, 右边口袋 <[hidden email]> wrote:

> Guys,
>
>     I test below code and found the key(key1) still exists after 100
> milliseconds(even longer), seems cache.WithExpiryPolicy does not work?
>
>     Can someone tell how to set ExpiryPolicy in config.xml? Thanks much!
>
>     Code snippet:
>     public static void WriteTestCache(IIgnite ignite)
>         {
>             try
>             {
>                 cache = ignite.GetOrCreateCache<string,
> string>("cache_test");
>                 cache.WithExpiryPolicy(new
> ExpiryPolicy(TimeSpan.FromMilliseconds(100),
>                 TimeSpan.FromMilliseconds(100),
> TimeSpan.FromMilliseconds(100)));
>
>                 cache.Put("key1", "value1");
>             }
>             catch (Exception ex)
>             {
>                 Console.WriteLine("IgniteHttpTest:WriteTestCache, ex {0}",
> ex);
>             }
>         }
>
>
>
> --
> View this message in context:
> http://apache-ignite-developers.2346864.n4.nabble.com/set-ExpiryPolicy-does-not-work-in-C-client-code-tp9833.html
> Sent from the Apache Ignite Developers mailing list archive at Nabble.com.
>