У меня есть следующий пользовательский кэш вывода Redis:
public class CustomRedisOutputCache : RedisOutputCacheProvider
{
public override object Add(string key, object entry, DateTime utcExpiry)
{
if (!HttpContextHelper.IsPreview())
{
return base.Add(key, entry, utcExpiry);
}
return entry;
}
public override void Set(string key, object entry, DateTime utcExpiry)
{
if (!HttpContextHelper.IsPreview())
{
base.Set(key, entry, utcExpiry);
}
}
}
Который настроен в web.config:
<caching>
<outputCache enableOutputCache="false" defaultProvider="CustomRedisOutputCache">
<providers>
<add name="CustomRedisOutputCache" type="xxx.xxx.Web.Caching.CustomRedisOutputCache" applicationName="xxx.xxx" connectionString="Redis" databaseId="4" throwOnError="false" retryTimeoutInMilliseconds="5000" loggingClassName="" loggingMethodName="" />
</providers>
</outputCache>
Что отлично работает, когда я использую атрибут outputcache:
[OutputCache(CacheProfile = CacheProfile.Medium, VaryByParam = "*")]
Однако я пытаюсь реализовать DonutCaching с помощью MVCDonutCaching Nuget Package и когда я изменяю атрибут на
[DonutOutputCache(CacheProfile = CacheProfile.Medium, VaryByParam = "*")]
Ошибка из-за следующей ошибки:
Невозможно создать экземпляр и инициализировать OutputCacheProvider типа 'xxx.xxx.Web.Caching.CustomRedisOutputCache'. Убедитесь, что вы указали полное имя типа.
В соответствии с документацией я должен иметь возможность использовать пользовательский поставщик кэша, так кто-нибудь знает, в чем проблема?
Глядя на исходный код, он, похоже, не работает:
try
{
Instance = (OutputCacheProvider)Activator.CreateInstance(Type.GetType(providerSettings.Type));
Instance.Initialize(providerSettings.Name, providerSettings.Parameters);
}
catch (Exception ex)
{
throw new ConfigurationErrorsException(
string.Format("Unable to instantiate and initialize OutputCacheProvider of type '{0}'. Make sure you are specifying the full type name.", providerSettings.Type),
ex
);
}
Полный исходный код для вышеуказанного класса
Обновление
После загрузки и пошагового выполнения исходного кода Type.GetType(providerSettings.Type)
возвращает ноль, даже если providerSettings.Type
равен xxx.xxx.Web.Caching.CustomRedisOutputCache и этот класс существует в исполняемом проекте xxx.xxx.Web