NutzCN Logo
问答 关于数据表的缓存问题
发布于 2179天前 作者 qq_cdeebfe2 2211 次浏览 复制 上一个帖子 下一个帖子
标签:
    // NutDaoExt是为了兼容1.b.52及以下版本, 53版或以上请直接用NutDao 
		type : "org.nutz.dao.impl.NutDaoExt", 
		args : [{refer:"dataSource"}],
		fields : {
			//executor : {refer:"cacheExecutor"} // executor是1.r.57.r3及以下版本的写法.
			interceptors : [{refer:"cacheExecutor"}, "log"] // 这是1.r.58及以上的写法
		}
	},
	cacheExecutor : {
		type : "org.nutz.plugins.cache.dao.DaoCacheInterceptor",
		fields : {
			cacheProvider : {refer:"cacheProvider"},
			cachedTableNames : ["tb_user", "tb_user_profile"], // 需要缓存的表
			enableWhenTrans : false, // 事务作用域内是否启用,默认false
			cache4Null : true // 是否缓存空值,默认true
		}
	},

这里的对表数据的缓存,是多长时间刷新一次?还是说只有系统重新加载才会刷新一次?

37 回复

不会刷新,但ehcache可以设置过期时间

@wendal 如果是网站首页访问比较频繁,数据该怎么缓存处理更合理呢?既能保持数据随着变化而变化又不至于一直频繁访问数据库~~?

@wendal ehcache可以设置过期时间可以解决上面的问题吗?

执行非select操作的时候,对应表的缓存就会请求

@wendal “执行非select操作的时候,对应表的缓存就会请求” 对这句话不理解,请指教~~

例如执行一条insert into user语句,那么user表的缓存就会全部清空(数据变化了),后续执行select拿到的是新数据(并缓存)

@wendal 你说的这个是ehcache 还是 sql级的缓存?

daocache这一层

有完整的例子可以参考吗 ?

这个不需要例子呀, daocache的机制就是这样

Ehcache示例配置
推荐分2个文件配置, 第一个是ehcache.js, 请务必留意里面的说明

与Shiro一起使用不是必须条件, daocache与shiro的联系只是共享一个CacheManager实例,这是可选的

为shiro和daocache分配不同的CacheManager实例是完全可以,请注意区分场景!!

var ioc = {
		cacheManager : {
			type : "net.sf.ehcache.CacheManager",
			factory : "net.sf.ehcache.CacheManager#getCacheManager",
			args : ["nutzbook"] // 对应shiro.ini中指定的ehcache.xml中定义的name
		}
		/*      
		// 如果不需要shiro初始化的Ehcache, 使用下面的方式配置
		cacheManager : {
			type : "net.sf.ehcache.CacheManager",
			factory : "net.sf.ehcache.CacheManager#create" // 这是工厂方法的强大之处
		}
		 */
};
第二个是dao.js, 区别只是cacheProvider指向的类不一样

var ioc = {
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : ["custom/"]
			}
		},
	    dataSource : {
	        type : "com.alibaba.druid.pool.DruidDataSource",
	        events : {
	        	create : "init",
	            depose : 'close'
	        },
	        fields : {
	            url : {java:"$conf.get('db.url')"},
	            username : {java:"$conf.get('db.username')"},
	            password : {java:"$conf.get('db.password')"},
	            testWhileIdle : true,
	            validationQuery : {java:"$conf.get('db.validationQuery')"},
	            maxActive : {java:"$conf.get('db.maxActive')"},
	            filters : "mergeStat",
	            connectionProperties : "druid.stat.slowSqlMillis=2000",
	        }
	    },
		dao : {
			type : "org.nutz.dao.impl.NutDaoExt",
			args : [{refer:"dataSource"}],
			fields : {
				//executor : {refer:"cacheExecutor"} // executor是1.r.57.r3及以下版本的写法.
				interceptors : [{refer:"cacheExecutor"}, "log"] // 这是1.r.58及以上的写法
			}
		},
		cacheExecutor : {
			type : "org.nutz.plugins.cache.dao.DaoCacheInterceptor", // 1.r.57.r3及以下版本用 CachedNutDaoExecutor
			fields : {
				cacheProvider : {refer:"cacheProvider"},
				cachedTableNames : [
				                    "t_use"
				                    ]
			}
		},
		// 基于Ehcache的DaoCacheProvider
		cacheProvider : {
			type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
			fields : {
				cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
			},
			events : {
				create : "init"
			}
		}
};

我按这个配置完成以后,在程序里怎么去使用,有例子吗 ?

透明的, 不需要特别的操作

t_use ?? 不是 t_user吗?

对,是t_user ,只要配置好表的名字,具体的查询代码那里不用处理了吗 ?

连续查2次, 会看到只出一次SQL, 期间没有非select操作的话.

2018-12-05 11:10:36,910 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'dao' from [app] 
2018-12-05 11:10:36,910 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'dicConfigManager' from [app] 
2018-12-05 11:10:36,912 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:125) ERROR - Error happend during start serivce!
org.nutz.ioc.IocException: IocBean[dicConfigManager] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:152)
	at com.cms.common.core.MainSetup.init(MainSetup.java:19)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4572)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5215)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: IocBean[dicConfigManager] fail at field=[dao]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 25 more
Caused by: org.nutz.ioc.IocException: IocBean[dao] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 27 more
Caused by: java.lang.RuntimeException: IocBean[dao] fail at field=[interceptors]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 30 more
Caused by: org.nutz.ioc.IocException: IocBean[cacheExecutor] For object [cacheExecutor] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:224)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.val.CollectionValue.get(CollectionValue.java:33)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 32 more
Caused by: org.nutz.ioc.ObjectLoadException: Wrong type name: 'org.nutz.plugins.cache.dao.DaoCacheInterceptor'
	at org.nutz.ioc.IocLoading.E(IocLoading.java:32)
	at org.nutz.ioc.IocLoading.map2iobj(IocLoading.java:59)
	at org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:86)
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:186)
	... 35 more
Caused by: java.lang.ClassNotFoundException: org.nutz.plugins.cache.dao.DaoCacheInterceptor
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:260)
	at org.nutz.lang.Lang.loadClass(Lang.java:2074)
	at org.nutz.ioc.IocLoading.map2iobj(IocLoading.java:55)
	... 38 more
2018-12-05 11:10:37,112 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:127) ERROR - try to depose ioc
2018-12-05 11:10:37,118 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:261) INFO  - org.nutz.ioc.impl.NutIoc@190181889 is closing. startup date [18-12-05 11:10:30.068]
2018-12-05 11:10:37,118 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:113) DEBUG - Depose object 'dataSource' ...
2018-12-05 11:10:37,154 com.alibaba.druid.pool.DruidDataSource.close(DruidDataSource.java:1447) INFO  - {dataSource-1} closed
2018-12-05 11:10:37,155 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:274) INFO  - org.nutz.ioc.impl.NutIoc@190181889 is deposed. startup date [18-12-05 11:10:30.068]
十二月 05, 2018 11:10:37 上午 org.apache.catalina.core.StandardContext filterStart
严重: Exception starting filter nutz
org.nutz.mvc.LoadingException: org.nutz.ioc.IocException: IocBean[dicConfigManager] throw Exception when creating
	at org.nutz.mvc.LoadingException$FC$9a86caf9ff5d3b587784fcdf555a4a7d.invoke(LoadingException.java)
	at org.nutz.lang.born.AbstractConstructorBorning.call(AbstractConstructorBorning.java:25)
	at org.nutz.lang.born.ConstructorBorning.born(ConstructorBorning.java:19)
	at org.nutz.lang.born.BornContext.doBorn(BornContext.java:60)
	at org.nutz.lang.Mirror.born(Mirror.java:1010)
	at org.nutz.lang.Lang.wrapThrow(Lang.java:201)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:135)
	at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
	at org.nutz.mvc.NutFilter._init(NutFilter.java:91)
	at org.nutz.mvc.NutFilter.init(NutFilter.java:69)
	at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
	at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
	at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
	at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4572)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5215)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1107)
	at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1841)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.nutz.ioc.IocException: IocBean[dicConfigManager] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:245)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:152)
	at com.cms.common.core.MainSetup.init(MainSetup.java:19)
	at org.nutz.mvc.impl.NutLoading.evalSetup(NutLoading.java:278)
	at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:121)
	... 19 more
Caused by: java.lang.RuntimeException: IocBean[dicConfigManager] fail at field=[dao]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 25 more
Caused by: org.nutz.ioc.IocException: IocBean[dao] throw Exception when creating
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:150)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:216)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 27 more
Caused by: java.lang.RuntimeException: IocBean[dao] fail at field=[interceptors]
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:40)
	at org.nutz.ioc.weaver.DefaultWeaver.fill(DefaultWeaver.java:56)
	at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:136)
	... 30 more
Caused by: org.nutz.ioc.IocException: IocBean[cacheExecutor] For object [cacheExecutor] - type:[]
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:224)
	at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
	at org.nutz.ioc.val.CollectionValue.get(CollectionValue.java:33)
	at org.nutz.ioc.weaver.FieldInjector.inject(FieldInjector.java:32)
	... 32 more
Caused by: org.nutz.ioc.ObjectLoadException: Wrong type name: 'org.nutz.plugins.cache.dao.DaoCacheInterceptor'
	at org.nutz.ioc.IocLoading.E(IocLoading.java:32)
	at org.nutz.ioc.IocLoading.map2iobj(IocLoading.java:59)
	at org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:86)
	at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:149)
	at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:186)
	... 35 more
Caused by: java.lang.ClassNotFoundException: org.nutz.plugins.cache.dao.DaoCacheInterceptor
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
	at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:260)
	at org.nutz.lang.Lang.loadClass(Lang.java:2074)
	at org.nutz.ioc.IocLoading.map2iobj(IocLoading.java:55)
	... 38 more

添加完上面的配置,报错了

需要添加daocache的jar/依赖

@wendal nutz-plugins-daocache 这个jar在哪里下载?

maven的话,添加依赖就行

@wendal

2018-12-05 11:51:05,285 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/ :
org.nutz.dao.DaoException: java.lang.NullPointerException
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._run(NutDaoRunner.java:92)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.run(NutDaoRunner.java:81)
	at org.nutz.dao.impl.DaoSupport.run(DaoSupport.java:240)
	at org.nutz.dao.impl.DaoSupport._exec(DaoSupport.java:252)
	at org.nutz.dao.impl.NutDao._count(NutDao.java:725)
	at org.nutz.dao.impl.NutDao.count(NutDao.java:687)
	at com.cms.business.services.ArticleInfoService.getArticleInfoByPager(ArticleInfoService.java:44)
	at com.cms.IndexCtl.index(IndexCtl.java:59)
	at com.cms.IndexCtl$FM$index$57b77988b38f0ceedad0a70c1e69c865.invoke(IndexCtl.java)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:30)
	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.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:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.java:176)
	at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:145)
	at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewriter.java:92)
	at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:394)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:789)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
	at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.getCache(EhcacheDaoCacheProvider.java:44)
	at org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider.get(EhcacheDaoCacheProvider.java:21)
	at org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:159)
	at org.nutz.plugins.cache.dao.DaoCacheInterceptor.filter(DaoCacheInterceptor.java:18)
	at org.nutz.dao.DaoInterceptorChain.doChain(DaoInterceptorChain.java:64)
	at org.nutz.dao.DaoInterceptorChain.invoke(DaoInterceptorChain.java:139)
	at org.nutz.dao.impl.sql.run.NutDaoRunner.runCallback(NutDaoRunner.java:158)
	at org.nutz.dao.impl.sql.run.NutDaoRunner._runWithoutTransaction(NutDaoRunner.java:125)
	... 51 more

数据查询的时候 这个语句pager.setRecordCount(dao().count(ArticleInfoModel.class, cnd)); 报空指针错误了

没使用shiro?仔细看注释

非shiro环境,获取cacheManager的配置有差异

@wendal

java.io.NotSerializableException: com.cms.business.models.Article

这个要怎么处理呢 ?

加序列化接口

@wendal nutz也用implents Serializable?吗

daocache默认是jdk序列化器,所以需要

@wendal 整合完成了,也不报错了,但是每次还是在查询数据库,是哪里还需要配置吗?

@wendal 我用的是dao().query() ,现在每次访问还是打印sql, 并没有从缓存中取数据

什么版本的nutz,配置怎么写的

@wendal

org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) DEBUG - Exception when parser SQL sql, skip cache detect!!

日志里面有这个错误

这个只是提示解析sql失败,不等于是报错

nutz 版本是 1.r.63,

var ioc = {
		
		conf : {
			type : "org.nutz.ioc.impl.PropertiesProxy",
			fields : {
				paths : ["custom/"]
			}
		},
        dataSource : {
            type : "com.alibaba.druid.pool.DruidDataSource",
            events : {
                create : "init",
                depose : 'close'
            },
            fields : {
                url : "jdbc:oracle:thin:@192.168.0.111:1521:orcl",
                driverClassName : 'oracle.jdbc.driver.OracleDriver',
                username : "test",
                password : "test",
                testWhileIdle : true,
                maxActive : 100
            }
        },
        dao : {
            type : "org.nutz.dao.impl.NutDao",
            args : [{refer:"dataSource"}],
            fields : {
				//executor : {refer:"cacheExecutor"} // executor是1.r.57.r3及以下版本的写法.
				interceptors : [{refer:"cacheExecutor"}, "log"] // 这是1.r.58及以上的写法
			}
        }
        cacheExecutor : {
			type : "org.nutz.plugins.cache.dao.DaoCacheInterceptor", // 1.r.57.r3及以下版本用 CachedNutDaoExecutor
			fields : {
				cacheProvider : {refer:"cacheProvider"},
				cachedTableNames : [
				                    "t_user",
				                    "t_article
				                    ]
			}
		},
		// 基于Ehcache的DaoCacheProvider
		cacheProvider : {
			type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
			fields : {
				cacheManager : {refer:"cacheManager"} // 引用ehcache.js中定义的CacheManager
			},
			events : {
				create : "init"
			}
		}
};

ehcahe.js

// 如果shiro和Ehcache独立配置使用,使用以下配置参数
		cacheManager : {
			type : "net.sf.ehcache.CacheManager",
			factory : "net.sf.ehcache.CacheManager#create"
		}

上面是配置,基本上是按你的说明配置的

@wendal

2018-12-05 15:39:43,265 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE NAME=?) T WHERE ROWNUM <= 1) WHERE RN > 0 
   
  For example:> "SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE NAME='ceshi') T WHERE ROWNUM <= 1) WHERE RN > 0 "
2018-12-05 15:39:55,401 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM t_article  WHERE PARENT_ID=?
    |                                1 |
    |----------------------------------|
    | 43ade54344514579bb68b5b083d9bfc9 |
  For example:> "SELECT * FROM t_article  WHERE PARENT_ID='43ade54344514579bb68b5b083d9bfc9'"
2018-12-05 15:39:55,422 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) DEBUG - Exception when parser SQL sql, skip cache detect!! SQL=SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE CLASS_ID=?  ) T WHERE ROWNUM <= 7) WHERE RN > 0 
2018-12-05 15:39:55,423 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE CLASS_ID=?  ) T WHERE ROWNUM <= 7) WHERE RN > 0 
    |                                1 | 2 |
    |----------------------------------|---|
    | 95c2a3a55b034038824281ef2b048821 | 1 |
  For example:> "SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE CLASS_ID='95c2a3a55b034038824281ef2b048821' ) T WHERE ROWNUM <= 7) WHERE RN > 0 "
2018-12-05 15:39:55,472 org.nutz.plugins.cache.dao.CachedNutDaoExecutor.exec(CachedNutDaoExecutor.java:110) DEBUG - Exception when parser SQL sql, skip cache detect!! SQL=SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE CLASS_ID=? ) T WHERE ROWNUM <= 7) WHERE RN > 0 
2018-12-05 15:39:55,472 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - SELECT * FROM (SELECT T.*, ROWNUM RN FROM ( SELECT * FROM t_article  WHERE CLASS_ID=? ) T WHERE ROWNUM <= 7) WHERE RN > 0 
    |                                1 | 2 |
    |----------------------------------|---|
    | 3e9aa67263c049c4850955981be9e244 | 1 |

还是在执行sql,echache好像没有起作用

@wendal 2018-12-05 15:51:03,263 net.sf.ehcache.store.disk.DiskStorageFactory.deleteFile(DiskStorageFactory.java:838) DEBUG - Failed to delete file %0054%0044%0053%0043_%0042%0048_%004e%004f%0054%0049%0043%0045_%0049%004e%0046%004f.data
2018-12-05 15:51:03,268 net.sf.ehcache.store.disk.DiskStorageFactory.deleteFile(DiskStorageFactory.java:838) DEBUG - Failed to delete file %0054%0044%0053%0043_%0042%0048_%004e%004f%0054%0049%0043%0045_%0049%004e%0046%004f.index
2018-12-05 15:51:03,272 net.sf.ehcache.store.disk.DiskStorageFactory.(DiskStorageFactory.java:170) DEBUG - Matching data file missing (or empty) for index file. Deleting index file C:\Users\ADMINI~1\AppData\Local\Temp\%0054%0044%0053%0043_%0042%0048_%004e%004f%0054%0049%0043%0045_%0049%004e%0046%004f.index
2018-12-05 15:51:03,275 net.sf.ehcache.store.disk.DiskStorageFactory.deleteFile(DiskStorageFactory.java:838) DEBUG - Failed to delete file %0054%0044%0053%0043_%0042%0048_%004e%004f%0054%0049%0043%0045_%0049%004e%0046%004f.index
2018-12-05 15:51:03,346 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) DEBUG - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE
2018-12-05 15:51:03,350 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) DEBUG - Mocking Pass-Through Statistic: LOCAL_OFFHEAP_SIZE_BYTES
2018-12-05 15:51:03,356 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) DEBUG - Mocking Pass-Through Statistic: WRITER_QUEUE_LENGTH
2018-12-05 15:51:03,358 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) DEBUG - Mocking Pass-Through Statistic: REMOTE_SIZE
2018-12-05 15:51:03,359 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardPassThruStatistics(ExtendedStatisticsImpl.java:224) DEBUG - Mocking Pass-Through Statistic: LAST_REJOIN_TIMESTAMP
2018-12-05 15:51:03,367 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: OFFHEAP_GET
2018-12-05 15:51:03,369 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: OFFHEAP_PUT
2018-12-05 15:51:03,370 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: OFFHEAP_REMOVE
2018-12-05 15:51:03,380 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: XA_COMMIT
2018-12-05 15:51:03,381 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: XA_ROLLBACK
2018-12-05 15:51:03,381 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: XA_RECOVERY
2018-12-05 15:51:03,383 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: CLUSTER_EVENT
2018-12-05 15:51:03,383 net.sf.ehcache.statistics.extended.ExtendedStatisticsImpl.findStandardOperationStatistics(ExtendedStatisticsImpl.java:206) DEBUG - Mocking Operation Statistic: NONSTOP

对oracle的分页查询支持得不好,所以不行-_-

@wendal

2018-12-05 15:50:49,032 net.sf.ehcache.config.ConfigurationHelper.createDefaultCacheDecorators(ConfigurationHelper.java:364) DEBUG - CacheDecoratorFactory not configured for defaultCache. Skipping for 't_user'

@wendal 好吧,非常感谢,耽误您宝贵时间

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