- MyCache.zip
- MyCache
- Data
- Lib
- Microsoft.Practices.EnterpriseLibrary.Caching.Cryptography.dll
- Microsoft.Practices.EnterpriseLibrary.Caching.Database.dll
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.EnterpriseLibrary.Data.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
- Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.xml
- Microsoft.Practices.ObjectBuilder2.dll
- MyCache.sln
- MyCacheAPI
- MyCacheService
- App_Data
- aspnet_client
- system_web
- 4_0_30319
- bin
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.ObjectBuilder2.dll
- MyCacheService.dll
- MyCacheServiceLib.dll
- CacheService.svc
- MyCacheService.csproj
- MyCacheService.csproj.user
- obj
- Debug
- TempPE
- Release
- TempPE
- Properties
- web.config
- Web.Debug.config
- Web.Release.config
- MyCacheServiceLib
- bin
- Debug
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.ObjectBuilder2.dll
- MyCacheServiceLib.dll
- Release
- Microsoft.Practices.EnterpriseLibrary.Caching.dll
- Microsoft.Practices.EnterpriseLibrary.Common.dll
- Microsoft.Practices.ObjectBuilder2.dll
- SimpleCacheLib.dll
- CacheEntry.cs
- CacheService.cs
- ICacheService.cs
- LockManager.cs
- MyCacheServiceLib.csproj
- MyCacheServiceLib.csproj.user
- obj
- Debug
- TempPE
- Release
- TempPE
- Properties
- SimpleCacheLib.csproj.user
- Site1
- Site2
- Site3
- Site4
|
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MyCacheAPI;
using System.Web.Caching;
using System.IO;
using System.Text;
using System.Data.SqlClient;
namespace DistributedCache
{
public partial class ViewPerformance : System.Web.UI.Page
{
MyCache cache = new MyCache();
protected void Page_Load(object sender, EventArgs e)
{
LoadDataFromMyCache();
}
/// <summary>
/// Load data from Cache, or read data and store in cache
/// </summary>
protected void LoadDataFromMyCache()
{
lblWebFarm.Text = ConfigurationManager.AppSettings["WebFarmId"];
string strData = cache.Get("Key") as string;
if (strData == null)
{
divCacheMiss.Visible = true;
string dependencyFilePath = GetDependencyFilePath();
DateTime startTimeForCache = DateTime.Now;
object Value = GetObjectFromFile(dependencyFilePath);
DateTime endTimeForCache = DateTime.Now;
cache.Add("Key", Value);
}
else
{
divCacheHit.Visible = true;
DateTime startTimeForCache = DateTime.Now;
StringBuilder sbOutput = new StringBuilder();
string data = cache.Get("Key").ToString();
DateTime endTimeForCache = DateTime.Now;
lblCacheRetrievalTime.Text = string.Format("Retrieved 2KB data <b>Single time</b> from MyCache in <b>{0}</b> milliseconds", (endTimeForCache - startTimeForCache).TotalMilliseconds);
startTimeForCache = DateTime.Now;
for (int i = 0; i < 100; i++)
{
data = cache.Get("Key").ToString();
}
endTimeForCache = DateTime.Now;
lblCacheRetrievalTimeFor100Data.Text = string.Format("Retrieved 2KB data <b>100 times</b> from MyCache in <b>{0}</b> milliseconds", (endTimeForCache - startTimeForCache).TotalMilliseconds);
for (int i = 0; i < 1000; i++)
{
data = cache.Get("Key").ToString();
}
endTimeForCache = DateTime.Now;
lblCacheRetrievalTimeFor1000Data.Text = string.Format("Retrieved 2KB data <b>1000 times</b> from MyCache in <b>{0}</b> milliseconds", (endTimeForCache - startTimeForCache).TotalMilliseconds);
}
}
/// <summary>
/// Get dependency file location
/// </summary>
/// <returns></returns>
private string GetDependencyFilePath()
{
string dependencyFilePath = Path.Combine(Path.Combine(Path.GetDirectoryName(Server.MapPath("")), "Data"), "Test.txt");
return dependencyFilePath;
}
/// <summary>
/// Read data from File
/// </summary>
/// <param name="dependencyFilePath"></param>
/// <returns></returns>
private object GetObjectFromFile(string dependencyFilePath)
{
object updatedValue = File.ReadAllText(dependencyFilePath);
return updatedValue;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.