C# 在CacheItemupdateCallback中调用WCF服务有什么缺点吗?

C# 在CacheItemupdateCallback中调用WCF服务有什么缺点吗?,c#,wcf,caching,C#,Wcf,Caching,在CacheItemUpdateCallback中有一个逻辑,特别是我在里面调用WCF服务,这有什么缺点吗 我希望我的应用程序在缓存中查找,并让更新回调完成更新昂贵的缓存项的工作。这是一个好方法吗 这是我的示例代码: public class CacheItemRepository : ICacheItemRepository { private readonly IItemService _service; private readonly ICacheManager _cac

在CacheItemUpdateCallback中有一个逻辑,特别是我在里面调用WCF服务,这有什么缺点吗

我希望我的应用程序在缓存中查找,并让更新回调完成更新昂贵的缓存项的工作。这是一个好方法吗

这是我的示例代码:

public class CacheItemRepository : ICacheItemRepository
{
    private readonly IItemService _service;
    private readonly ICacheManager _cacheManager;
    private static string CacheItemKey = "_itemkey_";

    public CacheItemRepository(IItemService service, ICacheManager cacheManager)
    {
        _service = service;
        _cacheManager = cacheManager;
    }

    public IList<Item> GetAllItem()
    {
        IList<Item> item = null;

        if (_cacheManager.TryGet(CacheItemKey, out item))
            return item;

        item = _service.GetAllItem();

        // Assumming I have CachePolicy here that expire every 15 secs.
        _cacheManager.Add(CacheItemKey, item, CachePolicy, CacheItemUpdateCallback );

        return item;
    }


    private void CacheItemUpdateCallback(string key, object value, CacheItemRemovedReason removedReason)
    {
        var itemList = value as IList<Item>;

        var items = _service.GetAllItem(); // Assume this return IList<Item>

        // Compare itemlist to items and if the two is not the same 
        // Assuming I have comparer here

        // Remove old cache
        _cacheManager.Remove(CacheItemKey);            

        // And add new one and assumming I have CachePolicy here that expire every 15 secs.            
        _cacheManager.Add(CacheItemKey, item, CachePolicy, CacheItemUpdateCallback ); 
    }
}
public类CacheItemRepository:ICacheItemRepository
{
专用只读IItemService\u服务;
专用只读ICacheManager(U cacheManager);
私有静态字符串CacheItemKey=“\u itemkey”;
公共CacheItemRepository(IItemService服务,ICacheManager cacheManager)
{
_服务=服务;
_cacheManager=cacheManager;
}
公共IList GetAllItem()
{
IList item=null;
if(_cacheManager.TryGet(CacheItemKey,out item))
退货项目;
item=_service.GetAllItem();
//假设我这里的缓存策略每15秒过期一次。
_添加(CacheItemKey、item、CachePolicy、CacheItemUpdateCallback);
退货项目;
}
私有void CacheItemUpdateCallback(字符串键、对象值、CacheItemRemovedRemovedRemovedReason)
{
var itemList=作为IList的值;
var items=_service.GetAllItem();//假设此返回为IList
//比较itemlist和items,如果两者不相同
//假设我这里有比较器
//删除旧缓存
_cacheManager.Remove(CacheItemKey);
//添加一个新的,假设我这里有缓存策略,每15秒过期一次。
_添加(CacheItemKey、item、CachePolicy、CacheItemUpdateCallback);
}
}