One cache with many value classes vs. several caches

classic Classic list List threaded Threaded
6 messages Options
alex.glau alex.glau
Reply | Threaded
Open this post in threaded view
|

One cache with many value classes vs. several caches

As in your Person-Organization example, you have cache (table) per bean class: PersonCache for Person and OrganizationCache for Organization. Technically, it is possible to have one shared cache for these two objects, like:
            CacheConfiguration<?, ?> sharedCacheCfg = new CacheConfiguration<>(SHARED_CACHE);

            orgCacheCfg.setCacheMode(CacheMode.PARTITIONED); // Default.
            orgCacheCfg.setIndexedTypes(UUID.class, Organization.class, AffinityKey.class, Person.class);

and join query will looks like:
        IgniteCache<AffinityKey<UUID>, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
        String joinSql =
            "from Person, Organization as org " +
            "where Person.orgId = org.id " +
            "and lower(org.name) = lower(?)";

        // Execute queries for find employees for different organizations.
        print("Following people are 'ApacheIgnite' employees: ",
            cache.query(new SqlQuery<AffinityKey<UUID>, Person>(Person.class, joinSql).
                setArgs("ApacheIgnite")).getAll());

What are advantages/disadvantages of these two ways of working with SQL queries?
vkulichenko vkulichenko
Reply | Threaded
Open this post in threaded view
|

Re: One cache with many value classes vs. several caches

Hi Alex,

While creating a shared cache is technically possible, it's not recommended usage of Ignite - you should always follow type-per-cache pattern. Ignite supports both cross-cache queries or cross-cache transactions, so there are no limitations with this approach.

Is there any particular reason why you're looking into creating a shared cache?

-Val
alex.glau alex.glau
Reply | Threaded
Open this post in threaded view
|

Re: One cache with many value classes vs. several caches

Hi Val,
No, I don't have any reason for using shared cache.
I simply thought if such feature exist so it has been developed for some reason. My question was what is this reason.
Alex.
Sergi Vladykin Sergi Vladykin
Reply | Threaded
Open this post in threaded view
|

Re: One cache with many value classes vs. several caches

Alex,

There are two main advantages to use cache per type:
1. It will work a bit faster for updates/removes if for cache we have small number of SQL tables.
2. You can switch PARTIOTIONED/REPLICATED mode and not to rewrite all the queries.

Sergi

2015-08-10 23:01 GMT+03:00 alex.glau <[hidden email]>:
Hi Val,
No, I don't have any reason for using shared cache.
I simply thought if such feature exist so it has been developed for some
reason. My question was what is this reason.
Alex.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/One-cache-with-many-value-classes-vs-several-caches-tp871p894.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

alex.glau alex.glau
Reply | Threaded
Open this post in threaded view
|

Re: One cache with many value classes vs. several caches

Hi Sergi,

I see that cache per type is better and recommended. The question was why there is option of multi-type cache? If multi-type cache does not have any advantage then why it was developed at all?

Alex.
Sergi Vladykin Sergi Vladykin
Reply | Threaded
Open this post in threaded view
|

Re: One cache with many value classes vs. several caches

It happened for historical reasons. Initially there was no ability to do cross-cache transactions, no ability to start new cache at runtime.
Now may be it would make sense to change this, but we keep it for backward compatibility and easier migration from older versions of GridGain.

Sergi

2015-08-11 9:24 GMT+03:00 alex.glau <[hidden email]>:
Hi Sergi,

I see that cache per type is better and recommended. The question was why
there is option of multi-type cache? If multi-type cache does not have any
advantage then why it was developed at all?

Alex.



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/One-cache-with-many-value-classes-vs-several-caches-tp871p903.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.