telnet 192.168.1.2 11211
stats
----------------------------------------
STAT pid 3932 --进程ID
STAT uptime 137
STAT time 1207723245
STAT version 1.2.1 --版本号
STAT pointer_size 32
STAT curr_items 999999 --当前ITEM 激活中的缓存的数量。
STAT total_items 999999 --从服务器开机以来的总的ITEM数量
STAT bytes 51888843
STAT curr_connections 5 --当前连接数
STAT total_connections 6 --总连接数
STAT connection_structures 6
STAT cmd_get 0 --进行GET的次数
STAT cmd_set 999999 --进行SET的次数
STAT get_hits 0 --命中数
STAT get_misses 0 --命中失败数
STAT bytes_read 24888902
STAT bytes_written 8000378
STAT limit_maxbytes 524288000 --分配的总内存空间
END
最后附加上网站结构和代码
前台界面
后台代码
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MemcachedProviders.Cache;// 引用类库MemcachedProviders
namespace My_MemcachedProviders
{
public partial class _Default : System.Web.UI.Page
{
List<Person> listp = new List<Person> { };
protected void Page_Load(object sender, EventArgs e)
{
//初始化几个人
for (int i = 0; i < 10; i++)
{
listp.Add(new Person() { Id = i.ToString(), Username = "随便什么值" + i });
}
}
//每次搜索的时候,判断缓存里面有没有这个人,有的话,直接读缓存,没有的话,就增加到缓存
protected void Search(object sender, EventArgs e)
{
string id = txtId.Text.Trim();
Person per = null;
for (int i = 0; i < listp.Count; i++)
{
if (listp.Id == id)
{
per = listp;
DistCache.DefaultExpireTime = 3000; //3秒
//如果缓存不存在,我们就把person这个实体放进去
if (DistCache.Get(per.Id) == null)
{
//存值 --不带过期时间的存储,Memcached将根据LRU来决定过期策略
DistCache.Add(per.Id, per);
//带过期时间的缓存,会根据过期时间来失效
//DistCache.Add(per.Id, per, DistCache.DefaultExpireTime); //如果这里2个都运行,那么第二行就相当于是对原来的数据的更新
litType.Text = "从数据库读,并增加到缓存";
litResult.Text = per.Username;
}
else
{
litType.Text = "从缓存来读";
Person temp = (Person)DistCache.Get(per.Id);
litResult.Text = temp.Username;
}
}
}
}
//清空缓存
protected void btnClear_Click(object sender, EventArgs e)
{
DistCache.RemoveAll();
litType.Text = "";
litResult.Text = "清除所有缓存";
}
}
}
代码下载地址
MemcachedProviders for .net 2.0 的客户端的实例 http://download.iyunv.com/detail/lihuabajie/4690044