Worked on the application cache, added request cache, changed some stuff over to be interfaces, added unit tests suite (need mroe) to test all caching providers.

Conflicts:
	src/Umbraco.Core/Cache/CacheProviderBase.cs
	src/Umbraco.Core/Cache/HttpRuntimeCacheProvider.cs
	src/Umbraco.Core/Cache/NullCacheProvider.cs
	src/Umbraco.Core/Cache/StaticCacheProvider.cs
This commit is contained in:
Shannon
2013-12-16 12:51:02 +11:00
parent 9105c08a4c
commit f11d4fbedd
21 changed files with 1012 additions and 344 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
namespace Umbraco.Core.Cache
{
/// <summary>
/// A cache provider that caches items in the HttpContext.Items
/// </summary>
internal class HttpRequestCacheProvider : DictionaryCacheProdiverBase
{
private readonly Func<HttpContextBase> _context;
public HttpRequestCacheProvider(HttpContext context)
{
_context = () => new HttpContextWrapper(context);
}
public HttpRequestCacheProvider(Func<HttpContextBase> context)
{
_context = context;
}
protected override DictionaryCacheWrapper DictionaryCache
{
get
{
var ctx = _context();
return new DictionaryCacheWrapper(
ctx.Items,
o => ctx.Items[o],
o => ctx.Items.Remove(o));
}
}
public override T GetCacheItem<T>(string cacheKey, Func<T> getCacheItem)
{
var ctx = _context();
var ck = GetCacheKey(cacheKey);
if (ctx.Items[ck] == null)
{
ctx.Items[ck] = getCacheItem();
}
return (T)ctx.Items[ck];
}
}
}