Я хочу запрограммировать основные операции кэширования CRUD (создание нового объекта, удаление его, обновление ...). Сначала я создаю объект и отображаю его имя, это мой код: (My cache name = "default")
web.config:
..........
<configuration>
<configSections>
<section name="dataCacheClient"
type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
Microsoft.ApplicationServer.Caching.Core,
Version=1.0.0.0, Culture=neutral,PublicKeyToken=31bf3856ad364e35" />
</configSections>
<dataCacheClient>
<hosts>
<host name="Amira-PC" cachePort="22233" />
</hosts>
</dataCacheClient>
......
Global.asax.cs:
using Microsoft.ApplicationServer.Caching;
namespace AppFabricCachingTest{
public class Global : System.Web.HttpApplication
{
public static string CacheFactoryName = "CacheFactory";
void Application_Start(object sender, EventArgs e)
{
// Code qui s'exécute au démarrage de l'application
var dcf = new DataCacheFactory();
Application[CacheFactoryName] = dcf;
DataCache myCache = dcf.GetCache("default");// cache name=mycache
object myCachedItem = new Object();
string myCachedItemKey = "MyCacheKey";
myCache.Add(myCachedItemKey, myCachedItem);
}
.....
`
Site.Master.cs
`
using Microsoft.ApplicationServer.Caching;
namespace AppFabricCachingTest
{
public partial class SiteMaster : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string GetCachedName()
{
string name = null;
string key ="MyCacheKey";
var dcf = Application[Global.CacheFactoryName] as DataCacheFactory;
if (dcf != null)
{
var cache = dcf.GetCache("default");
name = cache.Get(key) as string;
if (name == null)
{
name = "Windows Server App Fabric Cache ";
cache.Put(key, name);
}
else
{
name += " From Cache!";
}
}
else name = "dcf is NULL";
return name;
}
}
}
Сайт.Мастер:
<body>
<form runat="server">
<div class="page">
<div class="header">
<div class="title">
<h1>
<%= GetCachedName() %>
</h1>
</div>
...............
После запуска у меня всегда получалось "dcf is NULL", а не название объекта. Любая идея, пожалуйста,
Заранее спасибо