c# - 使用 Azure Redis 缓存重试策略

标签 c# caching azure azure-redis-cache

最近,我们从 Azure 角色缓存迁移到 Azure Redis 缓存(由 Azure 网站使用)。

我现在正在审查代码,有一行引起了我的注意。

using Microsoft.Practices.TransientFaultHandling;

// CODE

_retryPolicy = new RetryPolicy<CacheTransientErrorDetectionStrategy>(retryStrategy);

// CODE

_retryPolicy.ExecuteAction(() => dataCache.StringGet(fullCacheKey));

TransientFaultHandling 程序集中的 RetryPolicy 对 Redis 缓存有意义吗?或者,当我们使用 Azure Redis 而不是角色内缓存时,这段代码实际上不再有任何用途?

最佳答案

您的怀疑是正确的,CacheTransientErrorDetectionStrategy 是专门为 Windows Azure 缓存构建的。

http://www.projky.com/entlib/6.0/Microsoft/Practices/EnterpriseLibrary/TransientFaultHandling/CacheTransientErrorDetectionStrategy.cs.html

/// <summary>
/// Provides the transient error detection logic that can recognize transient faults when dealing with Windows Azure Caching.
/// </summary>

您可以保留 RetryPolicy,但需要将错误检测策略替换为您自己的 ITransientErrorDetectionStrategy 实现,例如检测超时异常。

关于c# - 使用 Azure Redis 缓存重试策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29661763/

相关文章:

asp.net - Asp.Net何时删除过期的缓存项?

oracle - Azure 数据工厂查找事件查询错误操作已超时

node.js - Bot Framework 从 Cosmos DB 检索用户地址以发送主动消息 NODE JS

c# - SQLite.Interop.DLL 如何使用非托管 DLL

java - 2 个具有相同 Id 的类如何更改属性并反射(reflect)在两个类中

java - 使用@Cacheable的Spring缓存在启动时不起作用@PostConstruct

Azure Function App - 尝试从 v2 工具发布到 v1 函数应用程序

c# - LINQ 中的排序和分组

c# - Visual Studio 中的“调试”和“发布”有什么区别?

c# - 在 WCF 服务中实现缓存