spy memcached spring demo

spring 配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd 
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd">
<bean id="memcachedClient" class="net.spy.memcached.spring.MemcachedClientFactoryBean"> 
<property name="servers" value="127.0.0.1:11211"/> 
<property name="protocol" value="BINARY"/> 
<property name="transcoder"> 
<bean class="net.spy.memcached.transcoders.SerializingTranscoder"> 
<property name="compressionThreshold" value="1024"/> 
</bean> 
</property> 
<property name="opTimeout" value="1000"/> 
<property name="timeoutExceptionThreshold" value="1998"/> 
<!-- <property name="hashAlg" value="KETAMA_HASH"/> --> 
<property name="locatorType" value="CONSISTENT"/> 
<property name="failureMode" value="Redistribute"/> 
<property name="useNagleAlgorithm" value="false"/> 
</bean> 
</beans>

测试类

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import net.spy.memcached.MemcachedClient;

public class MemcachedTest {
public static void main(String[] args) {
MemcachedClient cachedClient;
ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/applicationContext.xml");
cachedClient = (MemcachedClient)context.getBean("memcachedClient");
cachedClient.set("user", 200, "haha");//save user

System.out.println(cachedClient.get("user"));//haha
System.out.println(cachedClient.get("user1"));//null
}
}

需要的jar包,下面有些jar包非必须,部分未用到

spymemcached-2.10.1.jar

commons-beanutils-1.8.3.jar
commons-beanutils-bean-collections-1.8.3.jar
commons-beanutils-core-1.8.3.jar
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.6.jar
commons-logging-1.1.1.jar
log4j.jar
org.springframework.aop-3.0.5.RELEASE.jar
org.springframework.asm-3.0.5.RELEASE.jar
org.springframework.aspects-3.0.5.RELEASE.jar
org.springframework.beans-3.0.5.RELEASE.jar
org.springframework.context-3.0.5.RELEASE.jar
org.springframework.context.support-3.0.5.RELEASE.jar
org.springframework.core-3.0.5.RELEASE.jar
org.springframework.expression-3.0.5.RELEASE.jar
org.springframework.jdbc-3.0.5.RELEASE.jar
org.springframework.transaction-3.0.5.RELEASE.jar
org.springframework.web-3.0.5.RELEASE.jar
org.springframework.web.servlet-3.0.5.RELEASE.jar

说明:对于java使用memcached,需下载客户端

spymemcached客户端API:spymemcached client 
网址:http://code.google.com/p/spymemcached/

除了spy外,还有memcached client for java客户端

memcached client for java客户端API:memcached client for java 
网址:http://www.whalin.com/memcached

spy memcached spring demo

时间: 2024-10-08 20:00:06

spy memcached spring demo的相关文章

net spy memcached 使用demo

package memcached; import java.io.IOException; import java.net.InetSocketAddress; import net.spy.memcached.MemcachedClient; public class Client { private final int expiredSeconds = 100; private final InetSocketAddress server = new InetSocketAddress("

[Java] 第一个Spring Demo

1  Spring关键字: DI:Dependency Injection,依赖注入.依赖指的是调用关系.A调用B则A依赖于B.注入指的是A不再new B对象,而是由Spring容器来注入B对象. IoC:控制反转,对象不再由调用者来new,而是把new对象的任务交给Spring容器,Spring从XML中读取对象的属性值. AOP:面向切面变成(区别于面向对象编程OOP).so,切面是什么?一些公共行为? DAI:Spring整合了针对多种数据库的访问方式(含JDBC.OXM等) 框架融合:可

.net 应用Memcached 缓存 demo(非转载,文件下载地址有效)

一.准备: Memcaced服务端下载地址: http://files.cnblogs.com/sjns/memcached_en32or64.rar Memcaced 客户端类库:http://files.cnblogs.com/sjns/Memcached.ClientLibrary.rar 检测数据保存在哪个服务:securecrt(注:此软件没有用过,这里只记录以后有时间在验证) 二.安装Memcaced服务端 将memcached.exe复制到任意目录下.用cmd命令安装.(注:再wi

第一个Spring demo

参考Spring3.x企业实战 1.新建web工程chapter5,导入jar包.注意:cglib和commons-dbcp这两个包 2.设计数据库 t_login_log表结构(存放日志信息),主键递增 t_user表结构(存放用户信息),主键递增 3.设计包结构 4.domain对象 User.java package com.baobaotao.domain; import java.io.Serializable; import java.util.Date; public class

Spring MVC整合Memcached基于注释的实践使用

本文并不介绍memcached的安装使用,也不长篇大论哪个缓存框架性能好.而是结合自己实际开发,来谈谈自己的使用. 一.配置文件application-cache.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.or

Spting使用memcached

applicationContext.xml配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.s

Spring集成spymemcached

Spring集成spymemcachedMemcached的安装部署我就不介绍了!首先下载spymemcached,下载地址:jar:https://spymemcached.googlecode.com/files/spymemcached-2.10.3.jarjavadoc:https://spymemcached.googlecode.com/files/spymemcached-2.10.3-javadoc.jar源码:https://spymemcached.googlecode.co

关于 Memcached 的一些使用

关于Memcached的一些用法, Memcached 在Windows下的版本费了很大劲,才找到.win32,win64都有.本来想自己build的,但是Cygwin下载包也是费老劲了,下不下来. 在Linux上可以使用rpm/yum直接安装,很方面,如果喜欢自己build的话,那么官网就有源码,也很方便:http://memcached.org/ 也可以在github上找到:https://github.com/memcached/memcached 不过自己build的话Memcached

memcache+spring 配置

本文使用memcache开源客户端spymemcache跟spring结合. 操作步骤如下: 1. 引入spymemcache jar 包 (maven 设置pom) 具体sping pom该如何引用请查阅系统架构中配置 <dependency> <groupId>net.spy</groupId> <artifactId>spymemcached</artifactId> <version>2.11.4</version>