sfw0807
sfw0807
2014-05-22 18:05

hibernate memcached 二级缓存无效

  • memcached
  • hibernate

我用memcached配置的二级缓存
Spring-hibernate配置:
[code="java"]


true
${hibernate.dialect}
${hibernate.show_sql}
${hibernate.format_sql}
${hibernate.cache.region_prefix}
true
true
${hibernate.cache.provider_class}
${hibernate.cache.use_structured_entries}
${hibernate.memcached.servers}
${hibernate.memcached.memcacheClientFactory}


[/code]

系统启动提示 Starting MemcachedClient...

要缓存的类映射文件里加了

而且我debug发现对象已经加载到memcached中了
[code="java"]
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:304
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:303
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:302
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:301
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:299
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:413
quality.cache.memcache.com.akazam.directview.develop.model.Application:0:121
.............
[/code]
但是我在测试调用的时候,仍然是去数据库查询的,而不是直接从缓存中读取
郁闷了,不知道是怎么回事
测试代码:
[code="java"]
List applications = null;
//getApi().getDao()返回一个HibernateGenericDao
applications = (List)getApi().getDao().loadAll(Application.class);
applications = (List)getApi().getDao().getList(" from Application ", new Object[]{});
applications = (List) getApi().getDao().loadAsHql(" from Application ");
applications = (List) getApi().getDao().loadAsHql(" from Application ");
[/code]
控制台输出了四条mysql查询语句,根本没有调用缓存
求大神帮忙看看哪出问题了!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐