Contents
  1. 1. 注意事项
  2. 2. 关键命令
    1. 2.1. 运行相关
    2. 2.2. 安装相关
  3. 3. 构建和配置 结合Spring 的Cacheable注解整合

SpringCacheAnotation_Memcache的源码能跑的maven(含泪整理好的)
https://github.com/huangzhenshi/SSM_Memcache_Anotaion

参考blog,里面有安装配置相关
http://blog.csdn.net/l1028386804/article/category/5792345

博客,介绍telnet进入memcahe客户端,查看stored的信息
http://blog.sina.com.cn/s/blog_6f145be10102wlf8.html

注意事项

  • 配置文件当中不要有空格
  • 我的源码里面的配置形式和网上传了一大片的重写 cacheManager的不一样,我的更简洁啊

关键命令

运行相关

  • telnet 进入客户端操作界面
    telnet 127.0.0.1 11211

  • 设置name 标志为0 保存600秒,长度为5,回车后输入值 huang
    set name 0 600 5
    huang

  • get huang

  • delete name

  • flush_all

  • stats

  • 获取所有的items
    stats items (获取到所有的 item_id)
    stats cachedump item_id 0 (获取该 item_id 下面的所有item的详细信息)
    get $name
    http://www.ttlsa.com/memcache/memcache-list-all-keys/

安装相关

超级管理员权限 安装/开始/停止/卸载
d:\memcached memcached.exe -d install/start/stop/uninstall

构建和配置 结合Spring 的Cacheable注解整合

MAVEN
<!-- memcached引用包 -->
<!-- https://mvnrepository.com/artifact/com.googlecode.xmemcached/xmemcached -->
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>spring-cache</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.google.code.simple-spring-memcached</groupId>
<artifactId>xmemcached-provider</artifactId>
<version>3.1.0</version>
</dependency>
<!-- memcached引用包 end-->
application.xml
<cache:annotation-driven />
<bean name="cacheManager" class="com.google.code.ssm.spring.SSMCacheManager">
<property name="caches">
<set>
<bean class="com.google.code.ssm.spring.SSMCache">
<constructor-arg name="cache" index="0" ref="defaultCache"/>
<!-- 5 minutes -->
<constructor-arg name="expiration" index="1" value="300"/>
<!-- @CacheEvict(..., "allEntries" = true) doesn't work -->
<constructor-arg name="allowClear" index="2" value="false"/>
</bean>
</set>
</property>
</bean>
<bean name="defaultCache" class="com.google.code.ssm.CacheFactory">
<property name="cacheName" value="defaultCache"/>
<property name="cacheClientFactory">
<bean name="cacheClientFactory" class="com.google.code.ssm.providers.xmemcached.MemcacheClientFactoryImpl"/>
</property>
<property name="addressProvider">
<bean class="com.google.code.ssm.config.DefaultAddressProvider">
<property name="address" value="127.0.0.1:11211"/>
</bean>
</property>
<property name="configuration">
<bean class="com.google.code.ssm.providers.CacheConfiguration">
<property name="consistentHashing" value="true"/>
</bean>
</property>
</bean>

调用

@Cacheable(value = "defaultCache", key = "'getById'")
public User selectByPrimaryKey(long id) {
System.out.println("show_test");
User user = userDAO.selectByPrimaryKey(id);
return user;
}

Contents
  1. 1. 注意事项
  2. 2. 关键命令
    1. 2.1. 运行相关
    2. 2.2. 安装相关
  3. 3. 构建和配置 结合Spring 的Cacheable注解整合