Mybatis+memcached,二级缓存

1,启动 memcached 1.4.4-14

参照: http://blog.csdn.net/zhaotengfei36520/article/details/41315329

下载memcached的windows 32位版本程序,http://pan.baidu.com/s/1jIn1cO2
解压缩一个目录中,比如d:/memcached

找到exe执行,memcached.exe -d install,就会在window的服务里面进行管理了,设为自动启动。

修改参数,windows下需要通过修改注册表信息进行设置,打开注册表,找 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached 在其中有一个“ImagePath”项,值为: "D:\memcached\memcached.exe" -d runservice 在后面加上“-m 1024 -c 2048 -p 11210”。等即可。重启服务后生效


2,php 5.4.8.0与apache2.2集成
参照:http://blog.csdn.net/mlz_2/article/details/62430031

两个apache都安装到windows服务里,第二个这样执行命令:

httpd.exe -k install -n Apache2.2_PHP


3,memAdimin监控管理memcached
参照:http://www.cnblogs.com/huangxincheng/p/5471211.html
下载MemAdmin,http://www.junopen.com/memadmin/ ,memadmin-1.0.12.tar.gz,解压缩之后一个menadmin的文件夹,将它放到php发布的路径下面
下载memcache.dll,http://pan.baidu.com/s/1qY0gdFu ,使用的【php_memcache.dll(php5.4.7)】里面的dll文件。
将memcache.dll放到php/ext下面
在php.ini中增加extension=memcache.dll
php.exe -m 查看memcache.dll是否已加载成功


4,mybatis集成memcached

参考:http://www.mybatis.org/memcached-cache/

在maven的pom中增加
 <dependency>
    <groupId>org.mybatis.caches</groupId>
    <artifactId>mybatis-memcached</artifactId>
    <version>1.0.0</version>
  </dependency>

memcached的配置文件时memcached.properties,默认的配置如下

Property Default Description
org.mybatis.caches.memcached.keyprefix _mybatis_ any string identifier
org.mybatis.caches.memcached.servers localhost:11211 space separated list of ${host}:${port}
org.mybatis.caches.memcached.connectionfactory net.spy.memcached.DefaultConnectionFactory Any class that implementsnet.spy.memcached.ConnectionFactory
org.mybatis.caches.memcached.expiration the number of seconds in 30 days the expiration time (in seconds)
org.mybatis.caches.memcached.asyncget false flag to enable/disable the async get
org.mybatis.caches.memcached.timeout 5 the timeout when using async get
org.mybatis.caches.memcached.timeoutunit java.util.concurrent.TimeUnit.SECONDS the timeout unit when using async get
org.mybatis.caches.memcached.compression false if true, objects will be GZIP compressed before putting them to Memcached

  在mapper XML文件中配置cache,打开了这个mapper二级缓存的总开关,个别select中的userCache=false可以关闭某个查询的缓存
  <mapper namespace="org.acme.FooMapper">
  <cache type="org.mybatis.caches.memcached.MemcachedCache" />
  <select ... userCache=false>
  </select>
</mapper>


二级缓存会在这个mapper中的insert/update/delete之后,清空相关的缓存
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值