Lin,

As you can see at example you can use cache.withExpiryPolicy() to gain
cache wrapper with specific ExpiryPolicy.
This policy will be used during operations on this cache wrapper, only.

You can create as much wrappers as you need and put/get/etc entries using
them.

I recomend you to use CreatedExpiryPolicy to set ExpiryPolicy at entry
creation.
Comparision of ExpiryPolicies can be found here
https://apacheignite.readme.io/v1.4/docs/expiry-policies
Please have a look to other ExpiryPolicies, possible they will be more
suitable to your solution.
For example TouchedExpiryPolicy will renew timeout at each operation on
entry.








On Tue, Dec 1, 2015 at 3:33 PM, Vladimir Ershov <[email protected]>
wrote:

> Hi Lin,
> An expiry policy is working for all values, which were added through
> cacheWithExpiryPolicy according to the next example:
>
> IgniteCache<Object, Object> cacheWithExpiryPolicy = cache.withExpiryPolicy(
>     new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
>
>
> You are welcome to find an explaining example in the end of this message.
> It is also possible, that actually you are looking for something like
> eviction policy. Please take a look here then:
> https://apacheignite.readme.io/v1.5/docs/evictions
> Please, provide the feedback, if this answer was useful, or not.
> Thanks!
>
>     public void test() throws Exception {
>         Ignite ignite = startGrid(0); // some starting util method
>
>         CacheConfiguration<Integer, Integer> cfg = new
> CacheConfiguration<>();
>
>         cfg.setName(CACHE);
>         cfg.setCacheMode(CacheMode.PARTITIONED);
>         cfg.setRebalanceMode(CacheRebalanceMode.SYNC);
>         cfg.setBackups(1);
>
>         ignite.getOrCreateCache(cfg);
>
>         IgniteCache<Object, Object> cache1 = ignite.cache(null);
>
>         IgniteCache<Object, Object> cache2 = cache1.withExpiryPolicy(
>             new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 1)));
>
>         cache1.put(1, 1);
>         cache1.put(2, 2);
>         cache2.put(3, 3);
>
>         cache2.get(1); // *Does not affect ExpiryPolicy*.
>
>         U.sleep(2000);
>
>         assert cache1.get(1) == 1;
>         assert cache2.get(1) == 1; // *not Expired*
>         assert cache1.get(2) == 2;
>         assert cache1.get(3) == null; // *Expired*.
>
>     }
>
> On Tue, Dec 1, 2015 at 10:47 AM, Lin <[email protected]> wrote:
>
>> Hi,
>>
>> I have read the docs on jcache expiry policies, the policy  will be used
>> for each operation invoked on the returned cache instance.
>>
>> IgniteCache<Object, Object> cache = cache.withExpiryPolicy(
>>     new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
>>
>>
>> and searched the nabble faq and found
>>
>> http://apache-ignite-users.70518.x6.nabble.com/Does-IgniteCache-withExpiryPolicy-affect-existing-cache-entries-td1870.html
>>
>> As I know, the expiry policy is worked for all the entries in the cache.
>> I would like to specify different expiry policies for some different
>> entries,
>> How can I do?
>>
>> Thanks for you help.
>>
>>
>> Regards,
>>
>> Lin
>>
>>
>>
>

Reply via email to