使用Azure的AppFabric缓存服务时,最好的做法? [英] Best practice when using Azure AppFabric Caching Service?

查看:253
本文介绍了使用Azure的AppFabric缓存服务时,最好的做法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功地开始使用的Azure AppFabric缓存服务,但我不知道什么创造DataCacheFactory对象的最佳实践方式是。现在,我创造它每次调用到缓存中,但显​​然这不是做它的理想方式......

I have successfully started using Azure AppFabric Caching Service, but I' not sure what the best practice way of creating the DataCacheFactory object is. Now I'm creating it for every call into the cache, but apparently this is not the ideal way of doing it...

一些建议要求一个Singleton。但我不知道我知道如何做到这一点来实现(而不是实际Singleton类,但如何将其结合在一起)。

Some advise call for a Singleton. But I'm not sure I understand how this would be implemented (not the actual Singleton class, but how to tie it all together).

今天,我有一个使用Ninject为我创造了一个的CacheProvider类在那里我可以做得到/ PUT /删除操作。对于这些方法,我创建了DataCacheFactory对象,然后调用.GetDefaultCache()来获得数据高速缓存的对象,在这里我打电话PUT / GET /删除分别。我这样做的,看起来像这样一个方法:

Today I have a CacheProvider class that is created for me using Ninject where I can do Get/Put/Remove operations. For each of these methods I create the DataCacheFactory object and then call .GetDefaultCache() to get the DataCache object, where I call Put/Get/Remove respectively. I do this in a single method that looks like this:

private T Cache<T>(Func<DataCache, T> cacheAction)
{
    using (DataCacheFactory dataCacheFactory = new DataCacheFactory())
    {
        DataCache dataCache = dataCacheFactory.GetDefaultCache();
        return cacheAction(dataCache);
    }
}

我现在pretty肯定,这是不那么聪明,想法,我应该改为通过其中刚刚创建一次DataCacheFactory对象的单身获取数据高速缓存的对象。但如何将这个对象请求之间生存?又如何在Azure上用> 1实例的工作?

I'm now pretty sure that this is not-so-clever-idea, I should instead be getting the DataCache object via a Singleton where the DataCacheFactory object is just created once. BUT how will that object survive between requests? And how does that work with > 1 instance on Azure?

希望这一切有意义,与比我(3小时)更多的经验,有人可以帮助我。

Hope all this makes sense and that somebody with more experience than me (3 hours) can help me out.

推荐答案

辛格尔顿对象住在应用范围。简单地宣布在全球静态水平您的私人数据高速缓存的对象,提供一个属性得到实例化对象是否为空或返回对象,如果它不为空。

Singleton objects live at the application scope. Simply declare your private DataCache object on a global static level, provide a property Get that instantiates the object if it is null or returns the object if it is not null.

这样,你将支付每个应用程序的循环插装配置和高速缓存的连接只有一次的成本。

This way, you will be paying the cost of instrumenting configuration and connection of the cache only once per application recycle.

每个实例将实例化其自身的数据高速缓存的对象,这是好的。

Each instance will instantiate its own DataCache object and it is ok.

实际的数据,其中高速缓存存储不是存储在本地计算机的内存,但是在Azure中的专用缓存服务器的分布和大型快。

The actual data, where the cache is stored is not stored on your local machine's memory, but in Azure's dedicated cache servers that are distributed and mega-fast.

这篇关于使用Azure的AppFabric缓存服务时,最好的做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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