NutzCN Logo
问答 daocache的问题
发布于 3160天前 作者 qq_cd48ca64 1635 次浏览 复制 上一个帖子 下一个帖子
标签:

参数书里的配置的
dao : {
type : "org.nutz.dao.impl.NutDao", // 1.b.53或以上版本使用原版NutDao.
args : [{refer:"dataSource"}],
fields : {
executor : {refer:"cacheExecutor"}
}
},
cacheExecutor : {
type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
fields : {
cacheProvider : {refer:"cacheProvider"},
// 需要缓存的表名
cachedTableNames : ["example"]
}
},
// 基于Ehcache的DaoCacheProvider
cacheProvider : {
type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
fields : {
cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
},
events : {
create : "init"
}
}

var ioc = {
    cacheManager : {
        type : "net.sf.ehcache.CacheManager",
        factory : "net.sf.ehcache.CacheManager#create"
    }

};

    <dependency>
       <groupId>org.nutz</groupId>
       <artifactId>nutz</artifactId>
       <version>1.r.55</version>
    </dependency>
    <!-- Nutz 框架 Dao缓存插件-->
    <dependency>
       <groupId>org.nutz</groupId>
       <artifactId>nutz-plugins-daocache</artifactId>
       <version>1.b.53.r2</version>
    </dependency>
    <!-- Ehcache -->
    <dependency>
       <groupId>net.sf.ehcache</groupId>
       <artifactId>ehcache</artifactId>
       <version>2.10.1</version>
    </dependency>
    <!-- SLF4J -->
    <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
       <version>1.7.19</version>
    </dependency>

    然后我执行一个查询
    2016-03-22 13:28:08,764 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT * FROM example  LIMIT 0, 2 

2016-03-22 13:28:08,769 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT COUNT(*) FROM example
还是有SQL呢 我配置错了嘛

8 回复

第一次查肯定有sql啊

@wendal 我还是不太懂这个机制 有没有资料推荐一下

@wendal 每次都有呢
2016-03-22 14:26:57,217 [org.nutz.mvc.impl.UrlMappingImpl:org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92)] Found mapping for [GET] path=/example/list : ExampleAction.list(ExampleAction.java:23)
2016-03-22 14:26:57,217 [org.nutz.ioc.impl.NutIoc:org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153)] Get 'exampleAction'<class com.mxlvniao.upgrade.example.ExampleAction>
2016-03-22 14:26:57,218 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:44)] /mx_lvniao_upgrade/example/list
2016-03-22 14:26:57,218 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:45)] GET
2016-03-22 14:26:57,218 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:46)] text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
2016-03-22 14:26:57,219 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:47)] {"start":["0"],"limit":["2"]}
2016-03-22 14:26:57,220 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT * FROM example LIMIT 0, 2
2016-03-22 14:26:57,221 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT COUNT(*) FROM example
2016-03-22 14:27:17,680 [org.nutz.mvc.impl.UrlMappingImpl:org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:92)] Found mapping for [GET] path=/example/list : ExampleAction.list(ExampleAction.java:23)
2016-03-22 14:27:17,681 [org.nutz.ioc.impl.NutIoc:org.nutz.ioc.impl.NutIoc.get(NutIoc.java:153)] Get 'exampleAction'<class com.mxlvniao.upgrade.example.ExampleAction>
2016-03-22 14:27:17,681 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:44)] /mx_lvniao_upgrade/example/list
2016-03-22 14:27:17,682 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:45)] GET
2016-03-22 14:27:17,682 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:46)] text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
2016-03-22 14:27:17,682 [com.mxlvniao.common.nuzt.validation.ValidationProcessor:com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:47)] {"start":["0"],"limit":["2"]}
2016-03-22 14:27:17,683 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT * FROM example LIMIT 0, 2
2016-03-22 14:27:17,685 [org.nutz.dao.impl.sql.run.NutDaoExecutor:org.nutz.dao.impl.sql.run.NutDaoExecutor._runSelect(NutDaoExecutor.java:192)] SELECT COUNT(*) FROM example

在MainSetup.init方法中打开缓存日志

CachedNutDaoExecutor.DEBUG=true

如果一个sql没有被缓存:
1. 在事务内. 事务内的查询, 默认不查缓存
2. 表名没匹配.

@wendal 那是因为事务了因为我写了这个
{type : 'org.nutz.ioc.aop.config.impl.JsonAopConfigration',
fields : {
itemList : [
['com\.mxlvniao\.upgrade\..*Service','.+','ioc:transaction'],
]
}
}
这个配置能不能匹配到方法
比如 只有 save delete update这种方法才加事务

当然可以

 ['com\.mxlvniao\.upgrade\..*Service','.+','ioc:transaction'],

第3个参数 .+ 匹配的是方法名哦, 所以, 改成 ^(save|delete|update).*$

@wendal 这回报错了
java.io.NotSerializableException: com.mxlvniao.entity.dao.Example
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at java.util.LinkedList.writeObject(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.writeObject(Unknown Source)
at org.nutz.plugins.cache.dao.impl.convert.JavaCacheSerializer.from(JavaCacheSerializer.java:27)
at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.put(EhcacheDaoCacheProvider.java:28)
at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:149)
at org.nutz.dao.impl.DaoSupport$DaoExec.invoke(DaoSupport.java:316)
at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:59)
at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:239)
at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:271)
at org.nutz.dao.impl.NutDao.query(NutDao.java:465)
at com.mxlvniao.upgrade.example.ExampleService.getPageList(ExampleService.java:22)
at com.mxlvniao.upgrade.example.ExampleAction.list(ExampleAction.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at com.mxlvniao.common.nuzt.validation.ValidationProcessor.process(ValidationProcessor.java:93)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

@qq_cd48ca64 写得很清楚了,没实现序列化接口

添加回复
请先登陆
回到顶部