【发布时间】:2015-06-20 07:40:13
【问题描述】:
我正在按照教程 https://azure.microsoft.com/en-us/documentation/articles/cache-dotnet-how-to-use-service/ 使用 Azure Redis 缓存。我如何不使用使用 webconfig 来使用这个缓存?这是我的代码。
c#代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ApplicationServer.Caching;
using System.Data;
using System.Data.SqlClient;
namespace MoviesDB.CacheWrappers
{
public class AzureManagedCache
{
DataCache AzureCache = new DataCache("default");
public void Add(string sqlQuery, DataTable records)
{
List<Movie> movies = new List<Movie>();
movies = MovieDBContext.ConvertToMovies(records);
AzureCache.Add("sqlQuery", movies);
}
public void Delete(string sqlQuery)
{
AzureCache.Remove("sqlQuery");
}
public object Read(string sqlQuery)
{
var movie = AzureCache.Get("sqlQuery");
return movie;
}
}
}
和 webconfig.xml
<dataCacheClients>
<dataCacheClient name="default">
<!--To use the in-role flavor of Windows Azure Cache, set identifier to be the cache cluster role name
To use the Windows Azure Cache Service, set identifier to be the endpoint of the cache cluster-->
<autoDiscover isEnabled="true" identifier="******.cache.windows.net" />
<localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" />
<!--Use this section to specify security settings for connecting to your cache. This section is not required if your cache is hosted on a role that is a part of your cloud service.-->
<securityProperties mode="Message" sslEnabled="true">
<messageSecurity authorizationInfo="******" />
</securityProperties>
</dataCacheClient>
</dataCacheClients>
【问题讨论】: