惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
N
Netflix TechBlog - Medium
Google Online Security Blog
Google Online Security Blog
月光博客
月光博客
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
V
V2EX
腾讯CDC
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
M
MIT News - Artificial intelligence
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
Hugging Face - Blog
Hugging Face - Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
aimingoo的专栏
aimingoo的专栏
博客园 - 三生石上(FineUI控件)
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
The Cloudflare Blog
Blog — PlanetScale
Blog — PlanetScale
F
Full Disclosure
G
Google Developers Blog
罗磊的独立博客
Jina AI
Jina AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
J
Java Code Geeks
A
About on SuperTechFans
IT之家
IT之家
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
有赞技术团队
有赞技术团队
GbyAI
GbyAI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
The Register - Security
The Register - Security
U
Unit 42
D
Docker
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
NISL@THU
NISL@THU
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
博客园_首页
Google DeepMind News
Google DeepMind News

博客园 - Jwin

【转】最近ASP.NET WAP开发的一些情况 showModelessDialog()使用详解 showModalDialog和showModelessDialog的使用【转】 招聘兼职项目开发,寻找长期合作伙伴 转载:动态调用WebService(C#) 数据库优化不能不知道的工具:Database Engine Tuning Advisor【原创】 WebService传多个参数和返回多个参数的方法【转】 如何把文件上传到另外一台服务器【转】 memcached 介绍 asp.net实现显示在线会员 项目兼职:SQL Server数据库优化(价格面议) 做网站的人必须遵守的N大定律 ajax 脚本错误 'sys'未定义 (高价)项目兼职:开发qq机器人 关于博客园程序主页模板改进的若干建议 修改UrlRewrite以对域名进行重写,即实现二级或多级域名 【转】 对于URL重写,支持无后缀url请求【转】 ASP.NET 2.0的页面缓存功能介绍 [转] Awstats 安装使用说明(转)
转:分布式缓存系统Memcached简介与实践
Jwin · 2007-08-05 · via 博客园 - Jwin

缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载。缓存是解决这个问题的好办法。但是ASP.NET中的虽然已经可以实现对页面局部进行缓存,但还是不够灵活。此时Memcached或许是你想要的。

Memcached是什么?
Memcached是由Danga Interactive开发的,高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度。

Memcached能缓存什么?
通过在内存里维护一个统一的巨大的hash表,Memcached能够用来存储各种格式的数据,包括图像、视频、文件以及数据库检索的结果等。

Memcached快么?

非常快。Memcached使用了libevent(如果可以的话,在linux下使用epoll)来均衡任何数量的打开链接,使用非阻塞的网络I/O,对内部对象实现引用计数(因此,针对多样的客户端,对象可以处在多样的状态), 使用自己的页块分配器和哈希表, 因此虚拟内存不会产生碎片并且虚拟内存分配的时间复杂度可以保证为O(1).。

Danga Interactive为提升Danga Interactive的速度研发了Memcached。目前,LiveJournal.com每天已经在向一百万用户提供多达两千万次的页面访问。而这些,是由一个由web服务器和数据库服务器组成的集群完成的。Memcached几乎完全放弃了任何数据都从数据库读取的方式,同时,它还缩短了用户查看页面的速度、更好的资源分配方式,以及Memcache失效时对数据库的访问速度。

Memcached的特点
Memcached的缓存是一种分布式的,可以让不同主机上的多个用户同时访问, 因此解决了共享内存只能单机应用的局限,更不会出现使用数据库做类似事情的时候,磁盘开销和阻塞的发生。

Memcached的使用
Memcached服务器端的安装 (此处将其作为系统服务安装)
  下载文件:

memcached 1.2.1 for Win32 binaries (Dec 23, 2006)
   1 解压缩文件到c:\memcached
   2 命令行输入 'c:\memcached\memcached.exe -d install' 
   3 命令行输入 'c:\memcached\memcached.exe -d start' ,该命令启动 Memcached ,默认监听端口为 11211
  通过 memcached.exe -h 可以查看其帮助
二   .NET memcached client library
   下载文件:https://sourceforge.net/projects/memcacheddotnet/

   里面有.net1.1  和 .net2.0的两种版本  还有一个不错的例子。

三  应用

  1 将Commons.dll,ICSharpCode.SharpZipLib.dll,log4net.dll,Memcached.ClientLibrary.dll 等放到bin目录
  2 引用
Memcached.ClientLibrary.dll
  3 代码

 1 namespace Memcached.MemcachedBench
 2 {
 3     using System;
 4     using System.Collections;
 5 
 6     using Memcached.ClientLibrary;
 7 
 8     public class MemcachedBench 
 9     {
10         [STAThread]
11         public static void Main(String[] args) 
12         {
13             string[] serverlist = { "10.0.0.131:11211""10.0.0.132:11211" };
14 
15             //初始化池
16             SockIOPool pool = SockIOPool.GetInstance();
17             pool.SetServers(serverlist);
18 
19             pool.InitConnections = 3;
20             pool.MinConnections = 3;
21             pool.MaxConnections = 5;
22 
23             pool.SocketConnectTimeout = 1000;
24             pool.SocketTimeout = 3000;
25 
26             pool.MaintenanceSleep = 30;
27             pool.Failover = true;
28 
29             pool.Nagle = false;
30             pool.Initialize();
31 
32             // 获得客户端实例
33             MemcachedClient mc = new MemcachedClient();
34             mc.EnableCompression = false;
35 
36             Console.WriteLine("------------测  试-----------");
37             mc.Set("test""my value");  //存储数据到缓存服务器,这里将字符串"my value"缓存,key 是"test"
38 
39             if (mc.KeyExists("test"))   //测试缓存存在key为test的项目
40             {
41                 Console.WriteLine("test is Exists");
42                 Console.WriteLine(mc.Get("test").ToString());  //在缓存中获取key为test的项目
43             }
44             else
45             {
46                 Console.WriteLine("test not Exists");
47             }
48 
49             Console.ReadLine();
50 
51             mc.Delete("test");  //移除缓存中key为test的项目
52 
53             if (mc.KeyExists("test"))
54             {
55                 Console.WriteLine("test is Exists");
56                 Console.WriteLine(mc.Get("test").ToString());
57             }
58             else
59             {
60                 Console.WriteLine("test not Exists");
61             }
62             Console.ReadLine();
63             
64             SockIOPool.GetInstance().Shutdown();  //关闭池, 关闭sockets
65         }
66     }
67 }

  4 运行结果

   

   后记: 是个不错的东西 ,使用起来也很方便,php ,ruby 的项目中用这个的很多,但是.net项目中用的较少(恕俺孤陋寡闻) 。希望有兴趣的朋友们 多多交流 。 看到页首了么各位兄弟? 不用我多说了吧,挥动您的鼠标 轻轻按下左键吧