NutzCN Logo
问答 nutz-dao-cache 缓存问题
发布于 181天前 作者 Rekoe 151 次浏览 复制 上一个帖子 下一个帖子
标签:

貌似是缓存没有成功

17:57:35.624 [http-nio-8081-exec-4] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/api/user/add : UserModule.add(UserModule.java:32)
17:57:35.624 [http-nio-8081-exec-4] DEBUG org.nutz.ioc.impl.NutIoc - Get 'userModule'<class com.mysada.module.UserModule>
17:57:35.625 [http-nio-8081-exec-4] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
17:57:35.643 [http-nio-8081-exec-4] TRACE org.nutz.dao.impl.sql.run.NutDaoExecutor - ...DONE
17:57:35.647 [http-nio-8081-exec-4] DEBUG net.sf.ehcache.store.disk.Segment - put added 0 on heap
17:57:35.648 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault removed 0 from heap
17:57:35.650 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault added 0 on disk

ehcache.js文件

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

dao.js

var ioc = {
	conf : {
		type : "org.nutz.ioc.impl.PropertiesProxy",
		fields : {
			paths : [ "custom/" ]
		}
	},
	dataSource : {
		factory : "$conf#make",
		args : [ "com.alibaba.druid.pool.DruidDataSource", "db." ],
		type : "com.alibaba.druid.pool.DruidDataSource",
		events : {
			create : "init",
			depose : 'close'
		}
	},
	dao : {
		type : "org.nutz.dao.impl.NutDao",
		args : [ {
			refer : "dataSource"
		} ],
		fields : {
			executor : {
				refer : "cacheExecutor"
			}
		}
	},
	cacheExecutor : {
		type : "org.nutz.plugins.cache.dao.CachedNutDaoExecutor",
		fields : {
			cacheProvider : {
				refer : "cacheProvider"
			},
			cachedTableNames : [ "t_user" ],
			enableWhenTrans : false, // 事务作用域内不启用缓存,默认也是false
			db : "MYSQL"
		}
	},
	cacheProvider : {
		type : "org.nutz.plugins.cache.dao.impl.provider.EhcacheDaoCacheProvider",
		fields : {
			cacheManager : {
				refer : "cacheManager"
			}
		},
		events : {
			create : "init"
		}
	}
};
11 回复
18:00:40.119 [http-nio-8081-exec-6] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/api/user/add : UserModule.add(UserModule.java:32)
18:00:40.119 [http-nio-8081-exec-6] DEBUG org.nutz.ioc.impl.NutIoc - Get 'userModule'<class com.mysada.module.UserModule>
18:00:40.121 [http-nio-8081-exec-6] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
18:00:40.122 [http-nio-8081-exec-6] DEBUG net.sf.ehcache.store.disk.Segment - remove deleted 0 from heap
18:00:40.122 [http-nio-8081-exec-6] DEBUG net.sf.ehcache.store.disk.Segment - remove deleted 0 from disk
18:00:40.125 [http-nio-8081-exec-6] TRACE org.nutz.dao.impl.sql.run.NutDaoExecutor - ...DONE
18:00:40.125 [http-nio-8081-exec-6] DEBUG net.sf.ehcache.store.disk.Segment - put added 0 on heap
18:00:40.126 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault removed 0 from heap
18:00:40.127 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault added 0 on disk
18:00:50.004 [http-nio-8081-exec-7] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/api/user/add : UserModule.add(UserModule.java:32)
18:00:50.005 [http-nio-8081-exec-7] DEBUG org.nutz.ioc.impl.NutIoc - Get 'userModule'<class com.mysada.module.UserModule>
18:00:50.005 [http-nio-8081-exec-7] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
18:01:17.552 [http-nio-8081-exec-9] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/api/user/add : UserModule.add(UserModule.java:32)
18:01:17.553 [http-nio-8081-exec-9] DEBUG org.nutz.ioc.impl.NutIoc - Get 'userModule'<class com.mysada.module.UserModule>
18:01:17.554 [http-nio-8081-exec-9] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "

把调试日志开一下吧

CachedNutDaoExecutor.DEBUG = true;

18:14:32.859 [http-nio-8081-exec-2] DEBUG org.nutz.ioc.impl.NutIoc - Get 'dao'<>
18:14:32.915 [http-nio-8081-exec-2] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
18:14:32.928 [http-nio-8081-exec-2] DEBUG org.nutz.plugins.cache.dao.CachedNutDaoExecutor - sql = SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 , tables = [t_user]
18:14:32.929 [http-nio-8081-exec-2] DEBUG org.nutz.plugins.cache.dao.CachedNutDaoExecutor - KEY=1274644084:1:1:SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 :rekoe SQL=SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
18:14:32.966 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.store.MemoryStore - Initialized net.sf.ehcache.store.MemoryStore for t_user
18:14:32.981 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.DiskStorePathManager - Using diskstore path C:\Users\kouko\AppData\Local\Temp
18:14:32.981 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.DiskStorePathManager - Holding exclusive lock on C:\Users\kouko\AppData\Local\Temp\.ehcache-diskstore.lock
18:14:32.982 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.store.disk.DiskStorageFactory - Failed to delete file t_user.index
18:14:32.997 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.store.disk.DiskStorageFactory - Matching data file missing (or empty) for index file. Deleting index file C:\Users\kouko\AppData\Local\Temp\t_user.index
18:14:32.997 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.store.disk.DiskStorageFactory - Failed to delete file t_user.index
18:14:33.018 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.Cache - Initialised cache: t_user
18:14:33.018 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.config.ConfigurationHelper - CacheDecoratorFactory not configured for defaultCache. Skipping for 't_user'.
18:14:33.023 [http-nio-8081-exec-2] DEBUG org.nutz.plugins.cache.dao.CachedNutDaoExecutor - cache miss = SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
18:14:33.057 [http-nio-8081-exec-2] TRACE org.nutz.dao.impl.sql.run.NutDaoExecutor - ...DONE
18:14:33.067 [http-nio-8081-exec-2] DEBUG net.sf.ehcache.store.disk.Segment - put added 0 on heap
18:14:33.078 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault removed 0 from heap
18:14:33.078 [t_user.data] DEBUG net.sf.ehcache.store.disk.Segment - fault added 0 on disk

@wendal
是不是权限问题

不是, 这是nutz新版本吧, 用dao拦截器的方式配置, 不然sql依然打印, 看上去没生效, 实际上生效了.

https://github.com/nutzam/nutzmore/tree/master/nutz-plugins-daocache

@wendal
这样写后 还是会有 sql打印

dao : {
		type : "org.nutz.dao.impl.NutDao", 
		args : [{refer:"dataSource"}],
		fields : {
			interceptors : [{refer:"cacheExecutor"}, "log"]
		}
	}
18:24:15.720 [http-nio-8081-exec-2] DEBUG org.nutz.ioc.impl.NutIoc - Get 'dao'<>
18:24:15.746 [http-nio-8081-exec-2] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
18:24:15.765 [http-nio-8081-exec-2] TRACE org.nutz.dao.impl.sql.run.NutDaoExecutor - ...DONE
18:24:19.692 [http-nio-8081-exec-3] DEBUG org.nutz.mvc.impl.UrlMappingImpl - Found mapping for [GET] path=/api/user/add : UserModule.add(UserModule.java:32)
18:24:19.693 [http-nio-8081-exec-3] DEBUG org.nutz.ioc.impl.NutIoc - Get 'userModule'<class com.mysada.module.UserModule>
18:24:19.694 [http-nio-8081-exec-3] DEBUG org.nutz.dao.impl.sql.run.NutDaoExecutor - SELECT * FROM t_user  WHERE name=? LIMIT 0, 1 
    |     1 |
    |-------|
    | rekoe |
  For example:> "SELECT * FROM t_user  WHERE name='rekoe' LIMIT 0, 1 "
18:24:19.696 [http-nio-8081-exec-3] TRACE org.nutz.dao.impl.sql.run.NutDaoExecutor - ...DONE

是不是有事务???

没用用到

@wendal

@IocBean(fields = "dao")
public class UserService extends IdEntityService<User> {

	/**
	 * 添加账号
	 * 
	 * @param username
	 * @param password
	 * @return
	 */
	public boolean add(String username, String password) {
		if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
			return false;
		}
		User user = dao().fetch(getEntityClass(), Cnd.where("name", "=", username));
		if (Lang.isEmpty(user)) {
			user = new User();
			user.setName(username);
			user.setCreateTime(Times.now());
			user.setPassword(Lang.sha1(password));
			user.setSalt(R.UU32());
			dao().insert(user);
		}
		return true;
	}

	public User fetch(String username) {
		User user = dao().fetch(getEntityClass(), Cnd.where("name", "=", username));
		return user;
	}
}

拦截器模式下是这个呢,看清楚说明

type : "org.nutz.plugins.cache.dao.DaoCacheInterceptor",

嗯 好的 看到了

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