memcached安装及与spring集成

本文介绍了如何在Linux环境下安装Memcached,并通过Spring框架进行配置和集成。详细展示了applicationContext-memcached.xml文件中配置Memcached连接池参数的方法,以及通过Java代码进行测试的过程。

一、在linux安装memcached,首先按照libevent包,再安装memcached,启动时如果找不到libevent,运行LD_DEBUG=libs /usr/local/memcached/bin/memcached -v,


然后创建软链接ln -s path topath,就可以了启动了。

二、applicationContext-memcached.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:context="http://www.springframework.org/schema/context"
	xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
		http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
		http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd"
	default-lazy-init="true">
	
	<context:property-placeholder location="classpath:application.properties"/>
	
	<bean id="memcachedPool" class="com.whalin.MemCached.SockIOPool"
		factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
		<constructor-arg>
			<value>qwe</value>
		</constructor-arg>
		<property name="servers">
		<list>
			<value>${memcache.server}</value>
		</list>
		</property>
		<property name="initConn" value="${memcache.initConn}" />
		<property name="minConn" value="${memcache.minConn}" />
		<property name="maxConn" value="${memcache.maxConn}" />
		<property name="maxIdle" value="${memcache.maxIdle}" /> 
		<property name="maintSleep" value="${memcache.maintSleep}" />
		<property name="nagle" value="${memcache.nagle}" />
		<property name="socketTO" value="${memcache.socketTO}" />
		<property name="socketConnectTO" value="${memcache.socketConnectTO}"/>
	</bean>

	<bean id="cache" class="com.whalin.MemCached.MemCachedClient">
		<constructor-arg>
			<value>qwe</value>
		</constructor-arg>
	</bean>

</beans>
三、application.properties
#memcached configue
memcache.server=127.0.0.1:11211
memcache.initConn=20
memcache.minConn=10
memcache.maxConn=50
memcache.maxIdle=1800000
memcache.maintSleep=3000
memcache.nagle=false
memcache.socketTO=3000
memcache.socketConnectTO=3000


四、测试:

package com.csair.memcached;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.whalin.MemCached.MemCachedClient;
import com.whalin.MemCached.SockIOPool;

public class TestSpring {

	public static void main(String[] args) {
		String path = "applicationContext-memcached.xml";
		ApplicationContext context = new ClassPathXmlApplicationContext(path);
		SockIOPool pool = context.getBean("memcachedPool",SockIOPool.class);
		MemCachedClient cache = context.getBean("cache",MemCachedClient.class);
		cache.add("test", "ppt1");
		System.out.println(cache.get("test"));
	}
}


【电动车】基于多目标优化遗传算法NSGAII的峰谷分时电价引导下的电动汽车充电负荷优化研究(Matlab代码实现)内容概要:本文围绕“基于多目标优化遗传算法NSGA-II的峰谷分时电价引导下的电动汽车充电负荷优化研究”展开,利用Matlab代码实现优化模型,旨在通过峰谷分时电价机制引导电动汽车有序充电,降低电网负荷波动,提升能源利用效率。研究融合了多目标优化思想遗传算法NSGA-II,兼顾电网负荷均衡性、用户充电成本和充电满意度等多个目标,构建了科学合理的数学模型,并通过仿真验证了方法的有效性实用性。文中还提供了完整的Matlab代码实现路径,便于复现进一步研究。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的高校研究生、科研人员及从事智能电网、电动汽车调度相关工作的工程技术人员。; 使用场景及目标:①应用于智能电网中电动汽车充电负荷的优化调度;②服务于峰谷电价政策下的需求侧管理研究;③为多目标优化算法在能源系统中的实际应用提供案例参考; 阅读建议:建议读者结合Matlab代码逐步理解模型构建算法实现过程,重点关注NSGA-II算法在多目标优化中的适应度函数设计、约束处理及Pareto前沿生成机制,同时可尝试调整参数或引入其他智能算法进行对比分析,以深化对优化策略的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值