Pass configuration variables to Cache upon construction

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass configuration variables to Cache upon construction

Vlastimil Dolejš
Hi,
I have multiple databases in my app. There is SqlSessionFactory for each of these databases. I have some common Sql Mapper files which are included in each of these SqlSessionFactories. So far no problem.
Now I want to use cache (ehcache) in these mappers. If I add cache element to a common mapper, it will use single cache manager and data from different databases will be put in a single cache. There is no way how to tell cache to use different cache manager per SqlSessionFactory.

I think a proper way how to accomplish this would be put cache manager name to SqlSessionFactory configuration variables and then read this variable in Cache instance and use correct cache manager.
Currently this is not possible, because configuration variables are not passed to Cache instances upon creation.
So I want to create pull request, and I want to hear your opinion (mostly about backward compatibility)

Cache creation procedure would be:
  1. Create cache instance
  2. Set cache properties
  3. Set configuration variables
  4. Init cache - so you could do some initialization stuff

Setting cache properties is done by reflection - I think this way is not suitable for configuration variable so I propose to merge point 3 and 4 and add this method to Cache interface


void init(Properties configurationVariables);

Unfortunately this breaks compatibility with third party Cache implementations.


What do you think about it?


Vlasta

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pass configuration variables to Cache upon construction

Kazuki Shimizu
This fix via https://github.com/mybatis/mybatis-3/issues/816.

Thanks.

On Wednesday, October 26, 2016 at 12:02:37 AM UTC+9, Vlastimil Dolejš wrote:
Hi,
I have multiple databases in my app. There is SqlSessionFactory for each of these databases. I have some common Sql Mapper files which are included in each of these SqlSessionFactories. So far no problem.
Now I want to use cache (ehcache) in these mappers. If I add cache element to a common mapper, it will use single cache manager and data from different databases will be put in a single cache. There is no way how to tell cache to use different cache manager per SqlSessionFactory.

I think a proper way how to accomplish this would be put cache manager name to SqlSessionFactory configuration variables and then read this variable in Cache instance and use correct cache manager.
Currently this is not possible, because configuration variables are not passed to Cache instances upon creation.
So I want to create pull request, and I want to hear your opinion (mostly about backward compatibility)

Cache creation procedure would be:
  1. Create cache instance
  2. Set cache properties
  3. Set configuration variables
  4. Init cache - so you could do some initialization stuff

Setting cache properties is done by reflection - I think this way is not suitable for configuration variable so I propose to merge point 3 and 4 and add this method to Cache interface


void init(Properties configurationVariables);

Unfortunately this breaks compatibility with third party Cache implementations.


What do you think about it?


Vlasta

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.