Ответ 1
Я предполагаю, что детали вашего содержимого кэша или политики не совпадают. Не видя установки или вставки, трудно точно сказать, как это сделать.
Независимо от того, что две библиотеки имеют разные характеристики производительности, и какая из них лучше четко зависит от ситуации.
Вероятно, мой тест (код ниже) слишком прост, чтобы быть репрезентативным, но с его запуском на моей машине MemoryCache примерно в 10 раз быстрее.
class Program
{
const string myCacheKey = "foo";
static ICacheManager _elCache;
static MemoryCache _rtCache;
public static void InitCache()
{
_elCache = CacheFactory.GetCacheManager();
_elCache.Add(myCacheKey, new object());
_rtCache = new MemoryCache("cache");
_rtCache.Add(myCacheKey, new object(), new CacheItemPolicy());
}
public static string ElBenchmark(int n)
{
Stopwatch timer = new Stopwatch();
timer.Start();
for (int i = 0; i < n; i++)
{
object o = _elCache.GetData(myCacheKey);
}
timer.Stop();
return timer.ElapsedTicks.ToString();
}
public static string RtBenchmark(int n)
{
Stopwatch timer = new Stopwatch();
timer.Start();
for (int i = 0; i < n; i++)
{
object o = _rtCache.Get(myCacheKey);
}
timer.Stop();
return timer.ElapsedTicks.ToString();
}
static void Main(string[] args)
{
while (true)
{
InitCache();
StringBuilder sb = new StringBuilder();
System.Diagnostics.Debug.Write("EL: " + ElBenchmark(10000));
System.Diagnostics.Debug.Write("\t");
System.Diagnostics.Debug.Write("RT: " + RtBenchmark(10000));
System.Diagnostics.Debug.Write("\r\n");
}
}
}
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="cachingConfiguration"
type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
<cachingConfiguration defaultCacheManager="MyCacheManager">
<cacheManagers>
<add name="MyCacheManager" type="Microsoft.Practices.EnterpriseLibrary.Caching.CacheManager, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
expirationPollFrequencyInSeconds="60"
maximumElementsInCacheBeforeScavenging="50000"
numberToRemoveWhenScavenging="1000"
backingStoreName="NullBackingStore" />
</cacheManagers>
<backingStores>
<add type="Microsoft.Practices.EnterpriseLibrary.Caching.BackingStoreImplementations.NullBackingStore, Microsoft.Practices.EnterpriseLibrary.Caching, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="NullBackingStore" />
</backingStores>
</cachingConfiguration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>