首先就是先要配置Memcached,这个回头再写。

https://zhidao.baidu.com/question/809745125827797732.html

https://www.cnblogs.com/XZhao/p/6821121.html

using Memcached.ClientLibrary;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OAMS.Common
{
public class MemcacheHelper//声明一个类,里面放所用的方法之类的
{
private static readonly MemcachedClient mc = null;//MemcachedClient是添加的Memcached的dll里封装的
static MemcacheHelper()
{
//最好放在配置文件中
string[] serverlist = { "127.0.0.1:11211", "10.0.0.132:11211" };
//初始化池
SockIOPool pool = SockIOPool.GetInstance();
pool.SetServers(serverlist);

pool.InitConnections = 3;
pool.MinConnections = 3;
pool.MaxConnections = 5;

pool.SocketConnectTimeout = 1000;
pool.SocketTimeout = 3000;

pool.MaintenanceSleep = 30;
pool.Failover = true;

pool.Nagle = false;
pool.Initialize();

// 获得客户端实例
mc = new MemcachedClient();
mc.EnableCompression = false;
}

/// <summary>
/// 存储数据
/// </summary>
/// <param name="key"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool Set(string key, object value)
{
return mc.Set(key, value);
}
public static bool Set(string key, object value, DateTime time)
{
return mc.Set(key, value, time);
}
/// <summary>
/// 获取数据
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object Get(string key)
{
return mc.Get(key);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static bool Delete(string key)
{
if (mc.KeyExists(key))
{
return mc.Delete(key);

}
return false;

}
}
}

-------------------------------------------------------------------------

//将登录用户信息存储到Memcache中。
Common.MemcacheHelper.Set(sessionId, Common.SerializeHelper.SerializeToString(userInfo), DateTime.Now.AddMinutes(20));

//根据该值查Memcache.
object obj = Common.MemcacheHelper.Get(sessionId);

要在nuget里引用(安装) EnyimMemcached ,

https://blog.csdn.net/ma_jiang/article/details/61419460

  

记录一下Memcached的用法:的更多相关文章

  1. Mac linux 安装memcached服务 用法

    今天在Mac上安装memcached服务的时候 由于安装memcached之前需要安装libevent依赖包 所以使用brew install libevent 安装过程中报错 Warning: Yo ...

  2. 开发portlet中的一些问题记录,portlet:resourceURL用法,portlet中通过processAction方法传值

    在portlet页面中引入js或者css,通过c或者s标签 <!--jquery实际放的地方:/MyTask/WebContent/scripts/jquery-1.8.3.min.js--&g ...

  3. 记录一下set的用法

    set译为集合,是一个内部自动有序且不含重复元素的容器 有时出现需要去掉重复元素的情况 而且有可能因这些元素比较大或者类型不是int型而不能直接开散列表 在这种情况下就可以用set来保留元素本身而不考 ...

  4. 记录一个url_for的用法

    使用url_for生成url时,需要将url协议从http换成https时,就可以通过在函数中增加参数实现: url_for('secure_thingy', _external=True, _sch ...

  5. 记录一下Comparator的用法

    Collections.sort(res, new Comparator<ArrayList<Integer>>() {             @Override       ...

  6. memcached使用文档

    使用memcached进行内存缓存 通常的网页缓存方式有动态缓存和静态缓存等几种,在ASP.NET中已经可以实现对页面局部进行缓 存,而使用memcached的缓存比ASP.NET的局部缓存更加灵活, ...

  7. Memcached简介

    在Web服务开发中,服务端缓存是服务实现中所常常采用的一种提高服务性能的方法.其通过记录某部分计算结果来尝试避免再次执行得到该结果所需要的复杂计算,从而提高了服务的运行效率. 除了能够提高服务的运行效 ...

  8. Memcached+PHP+Mysql+Linux 实践

    首先确保你的服务器环境已经具备了memcached和lamp,关于在Linux上搭建memcahced+php环境可以参考我的另外一篇帖子( http://www.cnblogs.com/codeAB ...

  9. [转载]memcached完全剖析--1. memcached的基础

    转载自:http://charlee.li/memcached-001.html 翻译一篇技术评论社的文章,是讲memcached的连载.fcicq同学说这个东西很有用,希望大家喜欢. 发表日:200 ...

随机推荐

  1. Axios 使用时遇到的问题

    最近使用 vue 构建一个小项目,在使用 axios 发送 post 请求的时候,发现 axios 发送数据默认使用 json 格式,百度搜了下,更改 ContentType 不管用,最终问题原来是: ...

  2. 紫书 习题8-14 UVa 1616(二分+小数化分数+精度)

    参考了https://www.cnblogs.com/dwtfukgv/p/5645446.html (1)直接二分答案.说实话我没有想到, 一开始以为是贪心, 以某种策略能得到最优解. 但是想了很久 ...

  3. 洛谷 P3671 [USACO17OPEN]Where's Bessie? 贝西在哪呢

    P3671 [USACO17OPEN]Where's Bessie? 贝西在哪呢 题目背景 农夫John正在测试一个他新发明的全自动寻找奶牛无人机,它能够照一张农场的图片然后自动找出奶牛的位置. 不幸 ...

  4. @SpringBootApplication cannot be resolved to a type In STS

    @SpringBootApplication cannot be resolved to a type In STS 学习了:https://stackoverflow.com/questions/4 ...

  5. Memcached windows安装

    Memcached windows安装 如果出现提示: Microsoft Windows [版本 6.3.9600] (c) 2013 Microsoft Corporation.保留所有权利. D ...

  6. [Angular] Create a ng-true-value and ng-false-value in Angular by controlValueAccessor

    If you're coming from AngularJS (v1.x) you probably remember the ng-true-value and ng-false-value di ...

  7. 多线程相互排斥--mutex

    多线程之线程同步Mutex (功能与Critial Sections同样,可是属于内核对象,訪问速度较慢.能够被不同进程调用) 一 Mutex     相互排斥对象(mutex)内核对象可以确保线程拥 ...

  8. AppCan中标首都机场移动平台项目

    近日.正益无线AppCan依托东方航空.吉祥航空.国家电网.中化集团等大客户项目的丰富成功经验,凭借企业移动信息化建设的良好口碑.强大的移动化实施部署经验和高速响应的技术团队,在与多家国内外移动厂商比 ...

  9. swift 给导航添加item,实现界面的跳转

    //给导航添加item         var rightItem = UIBarButtonItem(title: "First", style: UIBarButtonItem ...

  10. 35.angularJS的ng-repeat指令

    转自:https://www.cnblogs.com/best/tag/Angular/ 1. <html> <head> <meta charset="utf ...