Memcached和Spring集成开发
2024-10-06 18:08:17
xml配置文件
<bean id="memcachedPool" class="com.danga.MemCached.SockIOPool"
factory-method="getInstance" init-method="initialize" destroy-method="shutDown">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
<property name="servers">
<list>
<value>192.168.174.104:</value>
</list>
</property>
<property name="initConn">
<value></value>
</property>
<property name="minConn">
<value></value>
</property>
<property name="maxConn">
<value></value>
</property>
<property name="maintSleep">
<value></value>
</property>
<property name="nagle">
<value>false</value>
</property>
<property name="maxIdle">
<value></value>
</property>
<property name="socketTO">
<value></value>
</property>
</bean>
<!--memcached client -->
<bean id="memCachedClient" class="com.danga.MemCached.MemCachedClient">
<constructor-arg>
<value>neeaMemcachedPool</value>
</constructor-arg>
</bean>
JAVA调用
@Primary
@Repository
public class GoodsMemDao implements GoodsDAO{ private final String MEM_PRE="goods_"; @Autowired
private GoodsMapperDAO goodsDao; @Autowired
private MemCachedClient memClient; public void create(GoodsModel m) {
goodsDao.create(m);
} public void update(GoodsModel m) {
goodsDao.update(m); Object obj=memClient.get(MEM_PRE+m.getUuid());
if(obj!=null){
memClient.set(MEM_PRE+m.getUuid(), m);
} } public void delete(Integer uuid) {
goodsDao.delete(uuid);
Object obj=memClient.get(MEM_PRE+uuid);
if(obj!=null){
memClient.delete(MEM_PRE+uuid);
}
} public GoodsModel getByUuid(Integer uuid) { Object obj=memClient.get(MEM_PRE+uuid);
if(obj !=null){
return (GoodsModel) memClient.get(MEM_PRE+uuid);
} GoodsModel goods=goodsDao.getByUuid(uuid);
memClient.set(MEM_PRE+uuid, goods); return goods;
} }
最新文章
- Socket与Http方式解析发送xml消息封装中间件jar包
- [20150925]Linux之文件系统与SHELL
- ueditor集成自己的ImageServer时出现错误的原因分析
- java yum安装的环境变量设置
- JavaScript Modules
- [2-sat]HDOJ1824 Let&#39;s go home
- Sencha Touch id 和 itemId
- (转载)关于ArrayList的5道面试题
- Median of Two Sorted Arrays 解答
- vi编辑器使用介绍
- about greenplum collection tool
- U盘安装VMware ESXi 6.0
- [Leetcode] DP -- Target Sum
- WEB 小案例 -- 网上书城(一)
- cut命令及参数企业案列讲解及awk对比
- 在Asp.Net Core中集成Kafka
- 评价指标整理:Precision, Recall, F-score, TPR, FPR, TNR, FNR, AUC, Accuracy
- Verilog设计异步FIFO
- ROS rosrun 调用 sudo 命令
- Python 内置函数sorted()在高级用法