You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by AndrewV <q1...@gmail.com> on 2019/01/21 14:12:58 UTC
Ignite with Spring cache
Hi everyone,
I integrated Ignite with my Spring application cache manager. Everything
works fine, but I need to implement custom cache revalidation logic.
Actually, my question is how to find something in a particular cache using
Spring Cache manager?
Thank you.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite with Spring cache
Posted by AndrewV <q1...@gmail.com>.
I found the mistake. I was testing this inside the real application and
caches had been evicted before I tried to iterate over caches. Thanks a lot
for your time.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite with Spring cache
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
You can do ignite().cache(cacheName).withKeepBinary().iterator() to capture
any entries if they are there. Can you try it and dump the contents
verbatim?
Regards,
--
Ilya Kasnacheev
ср, 23 янв. 2019 г. в 16:49, AndrewV <q1...@gmail.com>:
> Yes, I've tried ScanQuery. I understand that TextQuery is not good and I
> use
> it just for testing.
> But in both cases, I don't have any results.
>
> Here i get cache object:
> IgniteCache<Integer, Person> cache = Ignition.ignite().cache(cacheName);
>
> but I don't have any results when I try to find something inside when data
> definitely in the cache.
> Probably I made mistake but I don't have an idea how to debug it.
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Ignite with Spring cache
Posted by AndrewV <q1...@gmail.com>.
Yes, I've tried ScanQuery. I understand that TextQuery is not good and I use
it just for testing.
But in both cases, I don't have any results.
Here i get cache object:
IgniteCache<Integer, Person> cache = Ignition.ignite().cache(cacheName);
but I don't have any results when I try to find something inside when data
definitely in the cache.
Probably I made mistake but I don't have an idea how to debug it.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite with Spring cache
Posted by Ilya Kasnacheev <il...@gmail.com>.
Hello!
new TextQuery<Integer, Person>(Person.class, "PERSON_ID")
It looks that you are looking for a text "person_id" in all text fields of
Person.class. Are you sure this is something you want here? Perhaps you
wanted ScanQuery instead?
Regards,
--
Ilya Kasnacheev
вт, 22 янв. 2019 г. в 21:12, AndrewV <q1...@gmail.com>:
> I have a Spring application with Ignite cache configured according to
> samples
> - https://apacheignite-mix.readme.io/docs/spring-caching
>
> *My configured Spring bean:*
> --------------------------------------------------------------
> /@Bean
> public SpringCacheManager springCacheManager() {
> SpringCacheManager cm = new SpringCacheManager();
> IgniteConfiguration igniteConf = new IgniteConfiguration();
>
> igniteConf.setClientMode(true);
>
> /* Dynamic cache configuration */
> CacheConfiguration dynamicCacheConfig = new CacheConfiguration();
>
>
> dynamicCacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
> dynamicCacheConfig.setCacheMode(CacheMode.PARTITIONED);
> dynamicCacheConfig.setBackups(0);
> dynamicCacheConfig.setIndexedTypes(Integer.class, Object.class);
> cm.setDynamicCacheConfiguration(dynamicCacheConfig);
> return cm;
> }/
> --------------------------------------------------------------
>
>
> For caching I use Spring Cache annotation in service layer:
> *Service example*:
>
> /@Cacheable("getPersonById_cache")
> Person getPersonById(int id) {...}
>
>
> @Cacheable("getPersonsByParams_cache")
> List<Person> getPersonsByParams(...) {...}/
>
>
> *What I want to achieve:*
> When I'm changing Person entity I want to revalidate
> getPersonsByParams_cache, but just records (List) which contain this
> Person.
>
> So I decided to use Cache Queries (scan or text) to find matching records
> in
> the cache, something like that:
> /IgniteCache<Integer, Person> cache = Ignition.ignite().cache(cacheName);
>
> QueryCursor<javax.cache.Cache.Entry<Integer, Person>> result =
> cache.query(new TextQuery<Integer, Person>(Person.class, "PERSON_ID"));
>
> System.out.println(result.getAll());/
>
> but my result is always empty...
> Maybe we have another way to achieve that?
> Thanks.
>
>
>
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Ignite with Spring cache
Posted by AndrewV <q1...@gmail.com>.
I have a Spring application with Ignite cache configured according to samples
- https://apacheignite-mix.readme.io/docs/spring-caching
*My configured Spring bean:*
--------------------------------------------------------------
/@Bean
public SpringCacheManager springCacheManager() {
SpringCacheManager cm = new SpringCacheManager();
IgniteConfiguration igniteConf = new IgniteConfiguration();
igniteConf.setClientMode(true);
/* Dynamic cache configuration */
CacheConfiguration dynamicCacheConfig = new CacheConfiguration();
dynamicCacheConfig.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(Duration.TEN_MINUTES));
dynamicCacheConfig.setCacheMode(CacheMode.PARTITIONED);
dynamicCacheConfig.setBackups(0);
dynamicCacheConfig.setIndexedTypes(Integer.class, Object.class);
cm.setDynamicCacheConfiguration(dynamicCacheConfig);
return cm;
}/
--------------------------------------------------------------
For caching I use Spring Cache annotation in service layer:
*Service example*:
/@Cacheable("getPersonById_cache")
Person getPersonById(int id) {...}
@Cacheable("getPersonsByParams_cache")
List<Person> getPersonsByParams(...) {...}/
*What I want to achieve:*
When I'm changing Person entity I want to revalidate
getPersonsByParams_cache, but just records (List) which contain this Person.
So I decided to use Cache Queries (scan or text) to find matching records in
the cache, something like that:
/IgniteCache<Integer, Person> cache = Ignition.ignite().cache(cacheName);
QueryCursor<javax.cache.Cache.Entry<Integer, Person>> result =
cache.query(new TextQuery<Integer, Person>(Person.class, "PERSON_ID"));
System.out.println(result.getAll());/
but my result is always empty...
Maybe we have another way to achieve that?
Thanks.
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Ignite with Spring cache
Posted by "Maxim.Pudov" <pu...@gmail.com>.
It is not completely clear what exactly you are trying to achieve. Could you
describe your case in depth, share a piece of code or pseudo code?
If you want to iterate through all cache entries, you can use Ignite cache
API for that:
org.apache.ignite.Ignite#getOrCreateCache(java.lang.String).
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/