For those who are curious I did it like this...

Basically MyTuple is just "value" class that has two properties, the actual
value to be stored in the cache and a counter.

public class TestEntryProcessor implements EntryProcessor<String,
MyTuple, MyTuple> {
        @Override public MyTuple process(MutableEntry<String, MyTuple>
e, Object... args) {
            if(e.exists()) {
                MyTuple tuple = e.getValue();

                if(tuple.verificationCount-- == 0) {
                    e.remove();

                    return null;
                } else {
                    e.setValue(tuple);

                    return tuple;
                }
            } else {
                return null;
            }
        }
    }


On Thu, 23 Apr 2020 at 10:44, Ilya Kasnacheev <ilya.kasnach...@gmail.com>
wrote:

> Hello!
>
> Yes, I think you can update an entry with EntryProcessor while also
> returning it.
>
> Regards,
> --
> Ilya Kasnacheev
>
>
> ср, 22 апр. 2020 г. в 19:35, John Smith <java.dev....@gmail.com>:
>
>> Hi, akonresh understood, but then I would need another cache to keep
>> track of those counts.
>>
>> Ilya would a EntryProcessor allow for that with the invoke? Because
>> creating a wrapper I still need to track the counts.
>>
>> On Wed, 22 Apr 2020 at 12:10, Ilya Kasnacheev <ilya.kasnach...@gmail.com>
>> wrote:
>>
>>> Hello!
>>>
>>> I actually think that the optimal way is to have your own wrapper API
>>> which is only source of cache gets and which does this accounting under the
>>> hood.
>>>
>>> Then it can invoke the same cache entry to keep track of number of reads.
>>>
>>> Regards,
>>> --
>>> Ilya Kasnacheev
>>>
>>>
>>> вт, 21 апр. 2020 г. в 22:00, John Smith <java.dev....@gmail.com>:
>>>
>>>> Hi I want to store a key/value and If that key has been accessed more
>>>> than 3 times for example remove it. What is the best way to do this?
>>>>
>>>

Reply via email to