如何使用类列表集合中的Azure AppFabric缓存 [英] How to use Classes As List Collection in Azure AppFabric Caching

查看:98
本文介绍了如何使用类列表集合中的Azure AppFabric缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

H,
我使用的是Windows Azure的AppFabri缓存。
我在asp.ne t双项目。
一个将数据在缓存中,第二读取缓存。这两个项目都在2个不同的系统上运行。
我已经包含在这些项目中4 DLL。

H, I am using the Windows Azure AppFabri Caching. I have two project in asp.ne t . One to put data in cache and 2nd to read that cache. These Two project are running on 2 different systems. I have 4 dll included in these projects.

Microsoft.WindowsFabric.Common.dll
Microsoft.WindowsFabric.Data.Common.dll
Microsoft.ApplicationServer.Caching.Client.dll
Microsoft.ApplicationServer.Caching.Core.dll

Poject 1:要插入在高速缓存数据是使用以下code:数据被成功保存到缓存

Poject 1: To insert data in cache is using the following code:Data is saving to cache successfully

Default.aspx.cs:

Default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.ApplicationServer.Caching;

public partial class Default2 : System.Web.UI.Page
{
    public class Employee
    {
        public string Name { get; set; }
        public decimal Salary { get; set; }

    }
    protected static DataCacheFactory _factory = null;
    protected static DataCache _cache = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        PutDataIntoCache();

    }
    protected void PutDataIntoCache()
    {
        List<Employee> emp = new List<Employee>();
        try
        {

            emp.Add(new Employee { Name = "James", Salary = 20000 });
            PutCacheItem("55", emp);

        }
        catch (Exception ex)
        {

        }
    }
    protected void PutCacheItem(string key, object value)
    {

        try
        {
            _cache = GetDefaultCache();
            _cache.Put(key, value);
        }
        catch (Exception ex)
        {


        }
    }
    protected static DataCache GetDefaultCache()
    {
        _factory = new DataCacheFactory();
        _cache = _factory.GetDefaultCache();
        return _cache;

    }

}

现在我读的是另一个系统上运行的另一个项目缓存。
code为如下:

Now I am reading the cache in another project that is running on another system. Code is given below:

default.aspx.cs:

default.aspx.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.ApplicationServer.Caching;

public partial class Default2 : System.Web.UI.Page
{
    protected static DataCacheFactory _factory = null;
    protected static DataCache _cache = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        GetDataFromCache();

    }
    protected void GetDataFromCache()
    {
        _cache = GetDefaultCache();
        string key = "55";
        var item = _cache.Get(key);// Error is generation here
    }

    protected static DataCache GetDefaultCache()
    {
        _factory = new DataCacheFactory();
        _cache = _factory.GetDefaultCache();
        return _cache;

    }

}

这是错误的产生就行了_cache.Get(键)

An error is generating on the line _cache.Get(key)

The deserializer cannot load the type to deserialize because type 'System.Collections.Generic.List`1[[_Default2+Employee, App_Web_4xzswv4j, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]' could not be found in assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Check that the type being serialized has the same contract as the type being deserialized and the same assembly is used.

为什么这个错误是来了吗?
哪有我可以使用类的List集合添加/在高速缓存中读取。

Why this error is coming? How can Can I uses Classes as List collection to add/read in Cache.

推荐答案

我相信问题是,你的第二个项目没有定义Employee类。你应该在它和参考来自这两个项目同一个程序集定义一个类库的员工。

I believe the problem is that your second project doesn't define the Employee class. You should really define a class library with Employee in it and reference that same assembly from both projects.

这篇关于如何使用类列表集合中的Azure AppFabric缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆