java + memcached安装「建议收藏」

java + memcached安装

大家好,又见面了,我是全栈君。

一:安装

(临时获取上手windows实验)
1.下载memcached.exe , 上F:\memcached\ 下
2.在CMD在输入 “F:\memcached\memcached.exe -d install” 安装.
3.再输入:”F:\memcached\memcached.exe -d start” 启动。以后memcached将作为windows的一个服务每次开机时自己主动启动。

这样server端已经安装完成了。

二:java引包

下面的包都是网上找的, 传说是阿里某高人封的

alisoft-xplatform-asf-cache-2.5.1.jar

hessian-3.0.1.jar

stax-api-1.0.1.jar

wstx-asl-2.0.2.jar

三:測试文件

package com.xxx.util;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


import com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient;
import com.alisoft.xplatform.asf.cache.memcached.client.SockIOPool;
import com.xxx.entity.attrGrid.Records;


public class MemcachedManager
{
    //创建MemCachedClient全局对象
    private static MemCachedClient mcc = new MemCachedClient();
    
    static
    {
       //创建服务器列表及其权重
       String[] servers = {"127.0.0.1:11211"};
       Integer[] weights = {3};
       
       //创建Socket连接池对象
       SockIOPool pool = SockIOPool.getInstance();
       
       //设置服务器信息
       pool.setServers(servers);
       pool.setWeights(weights);
       pool.setFailover(true);
       
       //设置初始连接数、最小和最大连接数以及最大处理时间
       pool.setInitConn(5);
       pool.setMinConn(5);
       pool.setMaxConn(250);
       pool.setMaxIdle(1000*60*60*6);
       
       //设置主线程睡眠时间
       pool.setMaintSleep(30);
       
       //设置TCP參数、连接超时等
       pool.setNagle(false);
       pool.setSocketTO(3000);
       pool.setSocketConnectTO(0);
       pool.setAliveCheck(true);
       
       //初始化连接池
       pool.initialize();
       
       //压缩设置。超过指定大小(单位为K)的数据都会被压缩
       mcc.setCompressEnable(true);
       mcc.setCompressThreshold(64 * 1024);
    }
    
    /**
     * 无參构造
     */
    protected MemcachedManager ()
    { 
    }
    
    protected static MemcachedManager instance = new MemcachedManager();//单例
    public static MemcachedManager getInstance () 
    {
       return instance;
    }
    
    /**
     * 加入对象到缓存中。构成方法重载
     * @param key
     * @param value
     * @return
     */
    public boolean add(String key,Object value) 
    {
       return mcc.add(key, value);
    }
    public boolean add (String key,Object value,Date expiry) 
    {
       return mcc.add(key, value,expiry);
    }
    public boolean replace (String key,Object value) 
    {
       return mcc.replace(key, value);
    }
    public boolean replace (String key,Object value,Date expiry)
    {
       return mcc.replace(key, value, expiry);
    }
    
    /**
     * 依据指定的keyword获取对象
     */
    public Object get(String key) {
       return mcc.get(key);
    }
    
    /**
     * 利用MemCached对象将集合存入缓存。并从缓存中取出
     */
    public static void main(String[] args)
    {
       //得到MemcachedManager实例
       MemcachedManager cache = MemcachedManager.getInstance();
       
       //1插入
       List<Records> recordsList = new ArrayList<Records>();
       for( int i =0 ; i<5 ; i++ )
       {
    	   Records records = new Records();
    	   records.setPageSize(i);
    	   
    	   recordsList.add(records);
    	   cache.add("SELECT aaa FROM bbb WHERE "+i,records);
       }
       System.out.println("插入完毕==>");
       
       //2获取
       for( int i =0 ; i<9 ; i++ )
       {
    	   Records records = (Records)cache.get("SELECT aaa FROM bbb WHERE "+i);
    	   
    	   if( null == records  )
    	   {
    		   System.out.println("dao层 再去查"); 
    	   }
    	   else
    	   {   
    		   String str = records.getPageSize().toString();
    		   System.out.println("从缓存中取得的集合为:" + str);
    	   }
       }
    }
}

四:现象

2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.impl.DefaultCacheImpl – DefaultCache CheckService is start!
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ serializing for key: SELECT+aaa+FROM+bbb+WHERE+0 for class: com.tianditu.entity.attrGrid.Records
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ memcache cmd (result code): add SELECT+aaa+FROM+bbb+WHERE+0 8 0 451
 (STORED)
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ data successfully stored for key: SELECT+aaa+FROM+bbb+WHERE+0
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ serializing for key: SELECT+aaa+FROM+bbb+WHERE+1 for class: com.tianditu.entity.attrGrid.Records
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ memcache cmd (result code): add SELECT+aaa+FROM+bbb+WHERE+1 8 0 451
 (STORED)
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ data successfully stored for key: SELECT+aaa+FROM+bbb+WHERE+1
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ serializing for key: SELECT+aaa+FROM+bbb+WHERE+2 for class: com.tianditu.entity.attrGrid.Records
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ memcache cmd (result code): add SELECT+aaa+FROM+bbb+WHERE+2 8 0 451
 (STORED)
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ data successfully stored for key: SELECT+aaa+FROM+bbb+WHERE+2
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ serializing for key: SELECT+aaa+FROM+bbb+WHERE+3 for class: com.tianditu.entity.attrGrid.Records
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ memcache cmd (result code): add SELECT+aaa+FROM+bbb+WHERE+3 8 0 451
 (STORED)
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ data successfully stored for key: SELECT+aaa+FROM+bbb+WHERE+3
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ serializing for key: SELECT+aaa+FROM+bbb+WHERE+4 for class: com.tianditu.entity.attrGrid.Records
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ memcache cmd (result code): add SELECT+aaa+FROM+bbb+WHERE+4 8 0 451
 (STORED)
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ data successfully stored for key: SELECT+aaa+FROM+bbb+WHERE+4
插入完毕==>
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ deserializing class com.tianditu.entity.attrGrid.Records
从缓存中取得的集合为:0
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ deserializing class com.tianditu.entity.attrGrid.Records
从缓存中取得的集合为:1
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ deserializing class com.tianditu.entity.attrGrid.Records
从缓存中取得的集合为:2
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ deserializing class com.tianditu.entity.attrGrid.Records
从缓存中取得的集合为:3
2014 14:30:31 INFO  com.alisoft.xplatform.asf.cache.memcached.client.MemCachedClient – ++++ deserializing class com.tianditu.entity.attrGrid.Records
集合被从缓存制成:4
dao层 去检查
dao层 去检查
dao层 去检查
dao层 去检查

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/116654.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • 前端盲水印_前端代码review

    前端盲水印_前端代码review需求给图片加上看不到的水印,当通过其他的方式可以清楚的看到图片中暗藏的水印,以此方式追溯到泄密的人解决办法利用canvas实现图片和水印的绘制,具体过程如下:新建canvas,宽度和高度取要加水印的图片的宽度和高度 在该canvas上绘制要添加的水印文字,文字透明度设置要特别的低,但是当水印透明度小于等于0.003,不可恢复到水印。所以我们设置透明度要不得低于0.003 将该canvas转成img(为什么canvas要转成img?之前遇到canvas在移动端无法长按出现保存、转发等操作)

    2022年10月30日
  • 智慧职教云Java题库_云课堂智慧职教java职业证书题库答案

    智慧职教云Java题库_云课堂智慧职教java职业证书题库答案云课堂智慧职教java职业证书题库答案更多相关问题老子说“我有一颗愚人之心”,“若婴儿未孩”。下面哪一个选项最近此义:“大多数人都认为X是真的,所以X是真的。”属于()的论证方式。“大学语文”课程的前身是“大一国文”课程。()权益法下核算的长期股权投资,会导致投资企业投资收益发生增减变动的是( )“大众创业,万众创新”号召是在哪一年提出的?“大弦嘈嘈如急雨,小弦切切如私语。嘈嘈切切错杂弹,大珠小…

  • eclipse中文插件如何安装_eclipse不显示svn插件

    eclipse中文插件如何安装_eclipse不显示svn插件1、在eclipse中下载插件,地址如下:Name:Subclipse1.2.x(Eclipse3.2+)   URL: http://subclipse.tigris.org/update_1.2.xName:Subclipse1.0.x(Eclipse3.0/3.1)   URL: http://subclipse.tigris.org/up

    2022年10月11日
  • Response.ContentType 所有类型

    Response.ContentType 所有类型ez=>application/andrew-inset,hqx=>application/mac-binhex40,cpt=>application/mac-compactpro,doc=>application/msword,bin=>application/octet-stream,dms=>applicatio

  • idea集成gitee_git和idea

    idea集成gitee_git和ideaidea集成git,傻瓜式教程,超详细

    2022年10月29日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号