DOTNET的System.Web.Caching.Cache VS System.Runtime.Caching.MemoryCache [英] dotnet System.Web.Caching.Cache vs System.Runtime.Caching.MemoryCache

查看:185
本文介绍了DOTNET的System.Web.Caching.Cache VS System.Runtime.Caching.MemoryCache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,需要将数据存储在缓存中的一类。 本来我用它在一个asp.net应用程序,所以我用的System.Web.Caching.Cache。

I've got a class that needs to store data in a cache. Originally I used it in an asp.net application so I used System.Web.Caching.Cache.

现在我需要使用它在Windows服务。 现在,据我所知,我不应该使用asp.net缓存中没有asp.net应用程序,所以我一直在寻找进入的MemoryCache。

Now I need to use it in a Windows Service. Now, as I understand it, I should not use the asp.net cache in a not asp.net application, so I was looking into MemoryCache.

现在的问题是,他们是不兼容的,所以无论是我改变使用的MemoryCache在asp.net应用程序,或者我需要创建一个适配器,以便保证两个缓存实现有相同的接口(从ObjectCache可能得到并使用asp.net缓存内部?)

The problem is that they are not compatible, so either I change to use MemoryCache in the asp.net application, or I will need to create an adapter so ensure that the two cache implementations have the same interface (maybe derive from ObjectCache and use the asp.net cache internally?)

什么是一个asp.net使用的MemoryCache的含义是什么?

What are the implications of using MemoryCache in an asp.net?

Nadav

推荐答案

我将与你的第二个选项,并重构的东西一点点去。我想创建一个接口和两个供应商(这是你的适配器):

I would go with your second option and refactor things a little bit. I would create an Interface and two Providers (which are your adapters):

public interface ICachingProvider
{
    void AddItem(string key, object value);
    object GetItem(string key);
}

public AspNetCacheProvider : ICachingProvider
{
    // Adapt System.web.Caching.Cache to match Interface
}

public MemoryCacheProvider : ICachingProvider
{
    // Adapt System.Runtime.Caching.MemoryCache to match Interface
}

这篇关于DOTNET的System.Web.Caching.Cache VS System.Runtime.Caching.MemoryCache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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