网站架构之缓存应用(2)
2011-01-17 10:47
197 查看
实现篇
上一篇我主要总结了网站缓存中的一些基本概念,以及我对于网站架构缓存应用的架构实现思路,这篇主要分享下如何利用微软企业库来实现一二级缓存的缓存服务。
为了能够有效的管理缓存,需要对使用缓存方法上做一些规范,即要想使用缓存组件提供的服务,需要在指定的配置文件中按照一定的规则来配置缓存条目,不允许在配置之处使用缓存。下面先展示下一条Cache条目的配置:
代码
internal isRoc.Common.Cache.CacheProvider.IWebCacheProvider GetServiceClient(uint hash)
{
//Quick return if we only have one host.
if (clientArray.Length == 1)
{
return clientArray[0];
}
//New "ketama" host selection.
int i = Array.BinarySearch(hostKeysArray, hash);
//If not exact match...
if (i < 0)
{
//Get the index of the first item bigger than the one searched for.
i = ~i;
//If i is bigger than the last index, it was bigger than the last item = use the first item.
if (i >= hostKeysArray.Length)
{
i = 0;
}
}
return hostDictionary[hostKeysArray[i]];
}
总结:本文简单的介绍了如何利用微软企业库来实现具有两级缓存的缓存组件,上篇我提到过,实现一级缓存也可以采用memcached,采用memcached可以不用自己开发分布式客户端,目前有两个成熟的解决方案:1:Memcached.ClientLibrary2:EnyimMemcached。下篇我来介绍一级缓存如何通过memcached实现,以及如何让组件在一级缓存上即支持企业库也支持memcached。
上一篇我主要总结了网站缓存中的一些基本概念,以及我对于网站架构缓存应用的架构实现思路,这篇主要分享下如何利用微软企业库来实现一二级缓存的缓存服务。
为了能够有效的管理缓存,需要对使用缓存方法上做一些规范,即要想使用缓存组件提供的服务,需要在指定的配置文件中按照一定的规则来配置缓存条目,不允许在配置之处使用缓存。下面先展示下一条Cache条目的配置:
代码
internal isRoc.Common.Cache.CacheProvider.IWebCacheProvider GetServiceClient(uint hash)
{
//Quick return if we only have one host.
if (clientArray.Length == 1)
{
return clientArray[0];
}
//New "ketama" host selection.
int i = Array.BinarySearch(hostKeysArray, hash);
//If not exact match...
if (i < 0)
{
//Get the index of the first item bigger than the one searched for.
i = ~i;
//If i is bigger than the last index, it was bigger than the last item = use the first item.
if (i >= hostKeysArray.Length)
{
i = 0;
}
}
return hostDictionary[hostKeysArray[i]];
}
总结:本文简单的介绍了如何利用微软企业库来实现具有两级缓存的缓存组件,上篇我提到过,实现一级缓存也可以采用memcached,采用memcached可以不用自己开发分布式客户端,目前有两个成熟的解决方案:1:Memcached.ClientLibrary2:EnyimMemcached。下篇我来介绍一级缓存如何通过memcached实现,以及如何让组件在一级缓存上即支持企业库也支持memcached。
相关文章推荐
- 大型网站架构系列:缓存在分布式系统中的应用(三)
- 缓存在大型网站架构中的应用
- 网站架构之缓存应用(3)
- 细说缓存在大型网站架构中的应用
- 大型网站架构系列:缓存在分布式系统中的应用(二)
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 网站架构之缓存应用(1)概念篇
- 缓存在大型网站架构中的应用
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 大型网站架构:缓存在分布式系统中的应用(一)
- 大型网站架构系列:缓存在分布式系统中的应用(三)
- 大型网站架构系列:缓存在分布式系统中的应用(二)
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 网站架构之缓存应用
- 大型网站架构系列:缓存在分布式系统中的应用(三)
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 大型网站架构系列:缓存在分布式系统中的应用(一)
- 大型网站架构系列:缓存在分布式系统中的应用(二)
- 网站架构之缓存应用(2)实现篇