cache issue for multiple client datasouces query

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

cache issue for multiple client datasouces query

lohoso168
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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: cache issue for multiple client datasouces query

lohoso168
so basically, mybatis cache doesn't support multiple data source??

在 2019年1月29日星期二 UTC+8下午5:06:38,loho...@gmail.com写道:
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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: cache issue for multiple client datasouces query

Iwao AVE!
Hi,

I have not tested this, but if you pass client id as a parameter to the statement, it will be included in the cache key.
Let me know if it didn't work.

Regards,
Iwao

On Fri, Feb 1, 2019 at 18:23 <[hidden email]> wrote:
so basically, mybatis cache doesn't support multiple data source??

在 2019年1月29日星期二 UTC+8下午5:06:38,[hidden email]写道:
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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.

--
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: cache issue for multiple client datasouces query

lohoso168
Hi Iwao,
 
  Cache can work if we pass client id as a parameter, but it is impossible to pass client id for all statements, do we have any way to rewrite below createCacheKey method in BaseExecutor Class.

public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {

CacheKey cacheKey = new CacheKey();

cacheKey.update(ms.getId());

cacheKey.update(rowBounds.getOffset());

cacheKey.update(rowBounds.getLimit());

cacheKey.update(boundSql.getSql());

List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();

TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();

// mimic DefaultParameterHandler logic

for (ParameterMapping parameterMapping : parameterMappings) {

if (parameterMapping.getMode() != ParameterMode.OUT) {

Object value;

String propertyName = parameterMapping.getProperty();

if (boundSql.hasAdditionalParameter(propertyName)) {

value = boundSql.getAdditionalParameter(propertyName);

} else if (parameterObject == null) {

value = null;

} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {

value = parameterObject;

} else {

MetaObject metaObject = configuration.newMetaObject(parameterObject);

value = metaObject.getValue(propertyName);

}

cacheKey.update(value);

}

}

if (configuration.getEnvironment() != null) {

// issue #176

cacheKey.update(configuration.getEnvironment().getId());

}

return cacheKey;

}



在 2019年2月1日星期五 UTC+8下午6:18:09,Iwao AVE!写道:
Hi,

I have not tested this, but if you pass client id as a parameter to the statement, it will be included in the cache key.
Let me know if it didn't work.

Regards,
Iwao

On Fri, Feb 1, 2019 at 18:23 <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="mkGyjYVzDAAJ">loho...@...> wrote:
so basically, mybatis cache doesn't support multiple data source??

在 2019年1月29日星期二 UTC+8下午5:06:38,loho...@gmail.com写道:
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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 <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="mkGyjYVzDAAJ">mybatis-user...@googlegroups.com.
For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">https://groups.google.com/d/optout.

--
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: cache issue for multiple client datasouces query

Iwao AVE!
I do not think that is possible at the moment.
Assuming it is possible, how would you pass/retrieve client id? ThreadLocal?




On Sat, Feb 2, 2019 at 11:06 AM <[hidden email]> wrote:
Hi Iwao,
 
  Cache can work if we pass client id as a parameter, but it is impossible to pass client id for all statements, do we have any way to rewrite below createCacheKey method in BaseExecutor Class.

public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {

CacheKey cacheKey = new CacheKey();

cacheKey.update(ms.getId());

cacheKey.update(rowBounds.getOffset());

cacheKey.update(rowBounds.getLimit());

cacheKey.update(boundSql.getSql());

List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();

TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();

// mimic DefaultParameterHandler logic

for (ParameterMapping parameterMapping : parameterMappings) {

if (parameterMapping.getMode() != ParameterMode.OUT) {

Object value;

String propertyName = parameterMapping.getProperty();

if (boundSql.hasAdditionalParameter(propertyName)) {

value = boundSql.getAdditionalParameter(propertyName);

} else if (parameterObject == null) {

value = null;

} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {

value = parameterObject;

} else {

MetaObject metaObject = configuration.newMetaObject(parameterObject);

value = metaObject.getValue(propertyName);

}

cacheKey.update(value);

}

}

if (configuration.getEnvironment() != null) {

// issue #176

cacheKey.update(configuration.getEnvironment().getId());

}

return cacheKey;

}



在 2019年2月1日星期五 UTC+8下午6:18:09,Iwao AVE!写道:

Hi,

I have not tested this, but if you pass client id as a parameter to the statement, it will be included in the cache key.
Let me know if it didn't work.

Regards,
Iwao

On Fri, Feb 1, 2019 at 18:23 <[hidden email]> wrote:
so basically, mybatis cache doesn't support multiple data source??

在 2019年1月29日星期二 UTC+8下午5:06:38,[hidden email]写道:
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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.

--
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.

--
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: cache issue for multiple client datasouces query

lohoso168
Yes, ThreadLocal

在 2019年2月7日星期四 UTC+8上午2:00:41,Iwao AVE!写道:
I do not think that is possible at the moment.
Assuming it is possible, how would you pass/retrieve client id? ThreadLocal?




On Sat, Feb 2, 2019 at 11:06 AM <<a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="gY8pHqs5GQAJ">loho...@...> wrote:
Hi Iwao,
 
  Cache can work if we pass client id as a parameter, but it is impossible to pass client id for all statements, do we have any way to rewrite below createCacheKey method in BaseExecutor Class.

public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {

CacheKey cacheKey = new CacheKey();

cacheKey.update(ms.getId());

cacheKey.update(rowBounds.getOffset());

cacheKey.update(rowBounds.getLimit());

cacheKey.update(boundSql.getSql());

List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();

TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();

// mimic DefaultParameterHandler logic

for (ParameterMapping parameterMapping : parameterMappings) {

if (parameterMapping.getMode() != ParameterMode.OUT) {

Object value;

String propertyName = parameterMapping.getProperty();

if (boundSql.hasAdditionalParameter(propertyName)) {

value = boundSql.getAdditionalParameter(propertyName);

} else if (parameterObject == null) {

value = null;

} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {

value = parameterObject;

} else {

MetaObject metaObject = configuration.newMetaObject(parameterObject);

value = metaObject.getValue(propertyName);

}

cacheKey.update(value);

}

}

if (configuration.getEnvironment() != null) {

// issue #176

cacheKey.update(configuration.getEnvironment().getId());

}

return cacheKey;

}



在 2019年2月1日星期五 UTC+8下午6:18:09,Iwao AVE!写道:

Hi,

I have not tested this, but if you pass client id as a parameter to the statement, it will be included in the cache key.
Let me know if it didn't work.

Regards,
Iwao

On Fri, Feb 1, 2019 at 18:23 <[hidden email]> wrote:
so basically, mybatis cache doesn't support multiple data source??

在 2019年1月29日星期二 UTC+8下午5:06:38,loho...@gmail.com写道:
Hi,

   We need to process multiple clients in our project, so we use AbstractRoutingDataSource to complete that, but when we enable global cache in xml file, we find that when different clients process the same sql clause, the 2nd client db connection doesn't read from database, it directly get data from cache put by the 1st client query, is there any wayto create cache for different clients, I think we now use  BaseExecutor->createCacheKey to create cache key, can we pass client id into the cache key?


--
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 mybatis-user...@googlegroups.com.
For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">https://groups.google.com/d/optout.

--
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 <a onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;" href="javascript:" target="_blank" rel="nofollow" gdf-obfuscated-mailto="gY8pHqs5GQAJ">mybatis-user...@googlegroups.com.
For more options, visit <a onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" href="https://groups.google.com/d/optout" target="_blank" rel="nofollow">https://groups.google.com/d/optout.

--
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.