Cache生存周期对网站性能的影响
在这个开源项目中,我们可以看到这样一个选项,对于"Performance Settings",你可以选择:
- No Caching
- Light Caching
- Moderate Caching
- Heavy Caching
调节这些设置肯定能调校网站的性能,当到底有什么影响呢?技术上又是如何实现的呢?
查看源代码,我们发现PerformanceSettings 的值有三种,分别是0、1、3、6,那这几个值又是如何来控制cache的性能,从而调校整个网站的性能呢?
Public Enum PerformanceSettings
'The values of the enum are used to calculate
'cache settings throughout the portal.
'Calculating based on these numbers keeps
'the scaling linear for all caching.
NoCaching = 0
LightCaching = 1
ModerateCaching = 3
HeavyCaching = 6
End Enum
'The values of the enum are used to calculate
'cache settings throughout the portal.
'Calculating based on these numbers keeps
'the scaling linear for all caching.
NoCaching = 0
LightCaching = 1
ModerateCaching = 3
HeavyCaching = 6
End Enum
我们看看下面的代码就可以明白了:
Dim intCacheTimeout As Integer = 20 * Convert.ToInt32(Common.Globals.PerformanceSetting)
DataCache.SetCache(strCacheKey, objFile, TimeSpan.FromMinutes(intCacheTimeout))
DataCache.SetCache(strCacheKey, objFile, TimeSpan.FromMinutes(intCacheTimeout))
原来,系统使用PerformanceSettings的值来控制cache的生存时间,从而为不同特性的网站内容提供不同的cache生存时间,达到调校网站性能的目的。这的确是一个值得学习的精妙设计。
