You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by kevin <ke...@leonardo.com> on 2015/10/06 20:23:19 UTC
Cache read through when invoking EntryProcessor?
Hi,
When I invoke an entry processor on a particular cache key, it doesn't read
through to the persistence store to retrieve the value if it doesn't exist
in the cache.
Should I be expected to do a cache.get(key) before doing cache.invoke(key,
entryProcessor)?
Thanks
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Cache read through when invoking EntryProcessor?
Posted by kevin <ke...@leonardo.com>.
Hi,
I think I could've discovered it if the javadocs for IgniteCache.invoke(...)
had mentioned it. Right now, it's just referencing the JCache documentation,
which says
> If an {@link javax.cache.Cache.Entry} does not exist for the specified
> key, an attempt is made to load it (if a loader is configured)
Since I had configured the loader (I set a CacheStore), I was expecting it
to just work.
But Ignite doesn't mention anything about the cache configuration.
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1566.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Cache read through when invoking EntryProcessor?
Posted by Dmitriy Setrakyan <ds...@apache.org>.
On Tue, Oct 6, 2015 at 3:31 PM, vkulichenko <va...@gmail.com>
wrote:
> Kevin,
>
> You also need to set this property:
>
> cacheConfiguration.setLoadPreviousValue(true);
>
> It enables read-through for all update operations that also read previous
> value (getAndPut, replace, invoke, etc.).
>
Valentin, it would be great if user would get some warning in a log message
about it. Do you agree?
>
> -Val
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1560.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>
Re: Cache read through when invoking EntryProcessor?
Posted by kevin <ke...@leonardo.com>.
Thanks. I can confirm it works after setting that property.
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1561.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Cache read through when invoking EntryProcessor?
Posted by vkulichenko <va...@gmail.com>.
Kevin,
You also need to set this property:
cacheConfiguration.setLoadPreviousValue(true);
It enables read-through for all update operations that also read previous
value (getAndPut, replace, invoke, etc.).
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1560.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Cache read through when invoking EntryProcessor?
Posted by kevin <ke...@leonardo.com>.
Hi Val, I created a short test. I'm using Ignite 1.4
> public class Test {
> public static void main (String[] args) {
> Ignite ignite = Ignition.start();
> CacheConfiguration
> <
> Integer, String
> >
> cacheConfiguration = new CacheConfiguration<>("mycache");
> IgniteReflectionFactory
> <TestCacheStore>
> factory = new IgniteReflectionFactory<>(TestCacheStore.class, true);
> cacheConfiguration.setCacheStoreFactory(factory);
>
> cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
> cacheConfiguration.setReadThrough(true);
> cacheConfiguration.setWriteThrough(true);
> cacheConfiguration.setIndexedTypes(Integer.class, String.class);
>
> IgniteCache
> <
> Integer, String
> >
> cache = ignite.getOrCreateCache(cacheConfiguration);
>
> cache.invoke(1, (entry, arguments) -> {
> System.out.println("x " + entry.getValue());
> return null;
> });
>
> System.out.println("y " + cache.get(1));
>
> cache.invoke(1, (entry, arguments) -> {
> System.out.println("z " + entry.getValue());
> return null;
> });
> }
>
> public static class TestCacheStore extends CacheStoreAdapter
> <
> Integer, String
> >
> {
> @Override
> public String load(Integer key) throws CacheLoaderException {
> return "hi";
> }
>
> @Override
> public void write(Cache.Entry<? extends Integer, ? extends String>
> entry) throws CacheWriterException {
>
> }
>
> @Override
> public void delete(Object key) throws CacheWriterException {
>
> }
> }
> }
Output:
x null
x null
x null
y hi
z hi
z hi
z hi
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1559.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.
Re: Cache read through when invoking EntryProcessor?
Posted by vkulichenko <va...@gmail.com>.
Hi Kevin,
Can you show your cache configuration?
-Val
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Cache-read-through-when-invoking-EntryProcessor-tp1557p1558.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.