DataCacheFactory静态类 [英] DataCacheFactory static class

查看:84
本文介绍了DataCacheFactory静态类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在许多wcf服务中使用appfabric缓存。

Hi, i use the appfabric caching in many wcf services.

因为(我读过这个),新的DataCacheFactory是一个非常昂贵的指令,我使用的是class是缓存方法的包装器。

Because (i read this), the new DataCacheFactory is an instruction very expensive, i use a my class that is a wrapper for caching methods.


 public sealed class CacheManager
    {
        static string _namedCache = "";
        
        private static DataCacheFactory _factory= null;
        private static DataCache _cache = null;

        private static CacheManager _instance=null;

        private CacheManager(string cacheName)
        {
            _namedCache = cacheName;
            _factory = new DataCacheFactory();
            _cache = _factory.GetCache(_namedCache);
        }

        public static CacheManager Instance(string cacheName)
        {
            if (_instance == null)
            {
                lock (typeof(CacheManager))
                {
                    _instance = new CacheManager(cacheName);
                }
            }
            return _instance;
        }

推荐答案

代码看起来不错,如果缓存属性相同,你可以拥有所有缓存只有一个cachefactory,而不是每个缓存有一个缓存工厂。

Code looks good, If the cache properties are same, you could have only one cachefactory for all the caches, rather than having one cache factory per cache.


这篇关于DataCacheFactory静态类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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