Permalink
Browse files

Working on caching proxy updater

updated the cache disabler
  • Loading branch information...
gravypower committed Jan 17, 2013
1 parent 9e1e2bb commit cd0d841d50f86fccf2ebd896283babbe16f26e64
Showing with 501 additions and 209 deletions.
  1. +5 −0 Sites/Sitecore/Glass.Mapper.Sites.Sc/Glass.Mapper.Sites.Sc.ncrunchproject
  2. +0 −6 Sites/Sitecore/Glass.Mapper.Sites.Sc/layouts/TestSub.ascx.cs
  3. +0 −2 Source/Glass.Mapper.Sc/GlassConfig.cs
  4. +10 −45 Source/Glass.Mapper/AbstractService.cs
  5. +0 −2 Source/Glass.Mapper/AbstractTypeCreationContext.cs
  6. +47 −13 Source/Glass.Mapper/Caching/CacheDisabler.cs
  7. +6 −0 Source/Glass.Mapper/Caching/CacheKeyResolving/CacheKey.cs
  8. +1 −0 Source/Glass.Mapper/Caching/CacheKeyResolving/ICacheKey.cs
  9. +25 −3 Source/Glass.Mapper/Caching/ObjectCaching/AbstractObjectCache.cs
  10. +109 −30 Source/Glass.Mapper/Caching/ObjectCaching/CacheInformation.cs
  11. +6 −0 Source/Glass.Mapper/Caching/ObjectCaching/IAbstractObjectCache.cs
  12. +49 −0 Source/Glass.Mapper/Caching/Proxy/CacheLazyObjectInterceptor.cs
  13. +34 −8 Source/Glass.Mapper/Caching/Proxy/CacheMethodInterceptor.cs
  14. +7 −17 Source/Glass.Mapper/Caching/Proxy/CacheProxyGenerator.cs
  15. +1 −4 Source/Glass.Mapper/Caching/Proxy/CacheProxyGeneratorHook.cs
  16. +1 −1 Source/Glass.Mapper/Configuration/AbstractObjectCacheConfiguration.cs
  17. +10 −2 Source/Glass.Mapper/Context.cs
  18. +3 −2 Source/Glass.Mapper/Glass.Mapper.csproj
  19. +1 −4 Source/Glass.Mapper/{Caching → ObjectCaching}/Proxy/CacheInterfaceMethodInterceptor.cs
  20. +4 −5 Source/Glass.Mapper/Pipelines/ObjectConstruction/ObjectConstructionArgs.cs
  21. +2 −1 Source/Glass.Mapper/Pipelines/ObjectConstruction/Tasks/CreateConcrete/CreateConcreteTask.cs
  22. +5 −1 Source/Glass.Mapper/Pipelines/ObjectConstruction/Tasks/CreateConcrete/LazyObjectInterceptor.cs
  23. +6 −1 Source/Glass.Mapper/Pipelines/ObjectConstruction/Tasks/CreateInterface/CreateInterfaceTask.cs
  24. +3 −2 ...lass.Mapper/Pipelines/ObjectConstruction/Tasks/ObjectCachingResolver/ObjectCachingResolverTask.cs
  25. +3 −3 Source/Glass.Mapper/Pipelines/ObjectConstruction/Tasks/ObjectCachingSaver/ObjectCachingSaverTask.cs
  26. +38 −38 Tests/Integration Tests/Sitecore/Glass.Mapper.Sc.Integration/SetupSitecoreForTesting.cs
  27. +74 −19 Tests/Unit Tests/Glass.Mapper.Tests/Caching/CacheInformationFixture.cs
  28. +50 −0 Tests/Unit Tests/Glass.Mapper.Tests/Caching/ProxiesFixture.cs
  29. +1 −0 Tests/Unit Tests/Glass.Mapper.Tests/Glass.Mapper.Tests.csproj
@@ -17,4 +17,9 @@
<UseBuildPlatform></UseBuildPlatform>
<ProxyProcessPath></ProxyProcessPath>
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
+ <IgnoredTests>
+ <RegexTestSelector>
+ <RegularExpression>.*</RegularExpression>
+ </RegexTestSelector>
+ </IgnoredTests>
</ProjectConfiguration>
@@ -1,12 +1,6 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Web;
-using System.Web.UI;
-using System.Web.UI.WebControls;
using Glass.Mapper.Sc;
using Glass.Mapper.Sc.Configuration.Attributes;
-using Glass.Mapper.Sc.Integration;
using Glass.Mapper.Sites.Sc.Models;
namespace Glass.Mapper.Sites.Sc.layouts
@@ -142,8 +142,6 @@ public override void Configure(WindsorContainer container, string contextName)
Component.For<IObjectSavingTask>().ImplementedBy<StandardSavingTask>().LifestyleTransient(),
-
-
Component.For<AbstractObjectCacheConfiguration>().ImplementedBy<ObjectCacheConfiguration>().LifestyleTransient(),
Component.For<IAbstractObjectCache>().ImplementedBy<CacheTable<Guid>>().LifestyleTransient(),
Component.For<AbstractCacheKeyResolver<Guid>>().ImplementedBy<SitecoreCacheKeyResolver>().LifestyleTransient()
@@ -16,18 +16,8 @@ namespace Glass.Mapper
{
public abstract class AbstractService : IAbstractService
{
-
private IPerformanceProfiler _profiler;
- /// <summary>
- /// The list of tasks to be performed by the Object Construction Pipeline. Called in the order specified.
- /// </summary>
- private IEnumerable<IObjectConstructionTask> ObjectConstructionTasks { get; set; }
-
- /// <summary>
- /// The list of tasks to be performed by the Object Construction Pipeline. Called in the order specified.
- /// </summary>
- private IEnumerable<ObjectConstructionTask> ObjectConstructionTasks { get; set; }
public IPerformanceProfiler Profiler
{
get { return _profiler; }
@@ -41,9 +31,7 @@ public IPerformanceProfiler Profiler
}
}
- public Context GlassContext { get; private set; }
-
-
+ public Context GlassContext { get; private set; }
private TypeResolver _typeResolver;
@@ -52,7 +40,7 @@ public IPerformanceProfiler Profiler
private ObjectConstruction _objectConstruction;
private ObjectSaving _objectSaving;
-
+
public AbstractService()
: this(Context.Default)
{
@@ -69,17 +57,11 @@ public AbstractService(Context glassContext)
GlassContext = glassContext;
- if (GlassContext == null)
+ if (GlassContext == null)
throw new NullReferenceException("Context is null");
-
- ObjectConstructionTasks = glassContext.DependencyResolver.ResolveAllInOrder<ObjectConstructionTask>("Order");
- TypeResolverTasks = glassContext.DependencyResolver.ResolveAll<ITypeResolverTask>();
- ConfigurationResolverTasks = glassContext.DependencyResolver.ResolveAll<IConfigurationResolverTask>();
- ObjectSavingTasks = glassContext.DependencyResolver.ResolveAll<IObjectSavingTask>();
-
- var objectConstructionTasks = glassContext.DependencyResolver.ResolveAll<IObjectConstructionTask>();
- _objectConstruction = new ObjectConstruction(objectConstructionTasks);
+ var objectConstructionTasks = glassContext.DependencyResolver.ResolveAllInOrder<ObjectConstructionTask>("Order");
+ _objectConstruction = new ObjectConstruction(objectConstructionTasks);
var typeResolverTasks = glassContext.DependencyResolver.ResolveAll<ITypeResolverTask>();
_typeResolver = new TypeResolver(typeResolverTasks);
@@ -107,28 +89,17 @@ public object InstantiateObject(AbstractTypeCreationContext abstractTypeCreation
//run the pipeline to get the configuration to load
var configurationArgs = new ConfigurationResolverArgs(GlassContext, abstractTypeCreationContext, typeArgs.Result);
_configurationResolver.Run(configurationArgs);
-
+
if (configurationArgs.Result == null)
throw new NullReferenceException("Configuration Resolver pipeline did not return type.");
var config = configurationArgs.Result;
//Run the object construction
- _objectConstruction.Run(objectArgs);
+ var objectArgs = new ObjectConstructionArgs(GlassContext, abstractTypeCreationContext, config, this);
- var objectArgs = new ObjectConstructionArgs(GlassContext, abstractTypeCreationContext,
- config, this);
- if (DisableCache)
- {
- using (new CacheDisabler(objectArgs))
- {
- objectRunner.Run(objectArgs);
- }
- }
- else
- {
- objectRunner.Run(objectArgs);
- }
+
+ _objectConstruction.Run(objectArgs);
return objectArgs.Result;
@@ -157,17 +128,13 @@ public void SaveObject(AbstractTypeSavingContext abstractTypeSavingContext)
/// <param name="obj"></param>
/// <returns></returns>
public abstract AbstractDataMappingContext CreateDataMappingContext(AbstractTypeSavingContext creationContext);
-
-
- public bool DisableCache { get; set; }
}
public interface IAbstractService
{
- Context GlassContext { get; }
+ Context GlassContext { get; }
object InstantiateObject(AbstractTypeCreationContext abstractTypeCreationContext);
-
/// <summary>
/// Used to create the context used by DataMappers to map data to a class
/// </summary>
@@ -183,7 +150,5 @@ public interface IAbstractService
/// <param name="creationContext">The Saving Context</param>
/// <returns></returns>
AbstractDataMappingContext CreateDataMappingContext(AbstractTypeSavingContext creationContext);
-
- bool DisableCache { get; set; }
}
}
@@ -12,8 +12,6 @@ namespace Glass.Mapper
/// </summary>
public abstract class AbstractTypeCreationContext
{
-
-
public bool InferType { get; set; }
public bool IsLazy { get; set; }
public Type RequestedType { get; set; }
@@ -1,32 +1,66 @@
using System;
+using System.Web;
using Glass.Mapper.Pipelines.ObjectConstruction;
namespace Glass.Mapper.Caching
{
public class CacheDisabler:IDisposable
{
- private readonly ObjectConstructionArgs _args;
- private readonly IAbstractService _abstractService;
- public CacheDisabler(ObjectConstructionArgs args)
+ public static bool CacheDisabled
{
- this._args = args;
- args.DisableCache = true;
+ get
+ {
+ return HttpContext.Current != null ? ReturnFromHttpContxt() : ReturnFromThreadStatic();
+ }
+ set
+ {
+ if (HttpContext.Current != null)
+ {
+ SetToHttpContext(value);
+ }
+
+ SetToThreadStatic(value);
+ }
}
- public CacheDisabler(IAbstractService abstractService)
+ private static void SetToHttpContext(bool value)
{
- this._abstractService = abstractService;
- _abstractService.DisableCache = true;
+ HttpContext.Current.Items["Glass_CacheDisabled"] = value;
}
- public void Dispose()
+ private static bool ReturnFromHttpContxt()
+ {
+ if (HttpContext.Current.Items.Contains("Glass_CacheDisabled"))
+ {
+ {
+ return (bool)HttpContext.Current.Items["Glass_CacheDisabled"];
+ }
+ }
+ return false;
+ }
+
+ [ThreadStatic]
+ private static bool _threadStaticCacheDisabled;
+
+ private static void SetToThreadStatic(bool value)
{
- if(_args != null)
- _args.DisableCache = false;
+ _threadStaticCacheDisabled = value;
+ }
- if(_abstractService != null)
- _abstractService.DisableCache = false;
+ private static bool ReturnFromThreadStatic()
+ {
+ return _threadStaticCacheDisabled;
+ }
+
+ public CacheDisabler()
+ {
+ CacheDisabled = true;
+ }
+
+ public void Dispose()
+ {
+ CacheDisabled = false;
}
}
}
@@ -28,5 +28,11 @@ public override string ToString()
}
public abstract bool Equals(CacheKey<TIdType> other);
+
+
+ public object GetId()
+ {
+ return Id;
+ }
}
}
@@ -3,5 +3,6 @@
public interface ICacheKey
{
bool Equals(object other);
+ object GetId();
}
}
@@ -3,16 +3,18 @@
using System.Threading;
using Glass.Mapper.Caching.CacheKeyResolving;
using Glass.Mapper.Caching.ObjectCaching.Exceptions;
+using Glass.Mapper.Caching.Proxy;
using Glass.Mapper.Pipelines.ObjectConstruction;
using System.Linq;
namespace Glass.Mapper.Caching.ObjectCaching
{
public abstract class AbstractObjectCache<TIdType> : IAbstractObjectCache
{
- private readonly CacheInformation _cacheInformation = new CacheInformation();
+ private readonly CacheInformation<TIdType> _cacheInformation = new CacheInformation<TIdType>();
public string BaseCacheKey { get; set; }
-
+
+
public string DefaultBaseCacheKey
{
get { return "GlassObjectCahe"; }
@@ -26,7 +28,6 @@ public string DefaultBaseCacheKey
protected abstract void InternalAddObject(string objectKey, object objectForCaching);
protected abstract bool InternalClearCache();
-
protected AbstractObjectCache(string baseCacheKey)
{
BaseCacheKey = baseCacheKey;
@@ -64,6 +65,21 @@ public void AddObject(ObjectConstructionArgs args)
InternalAddObject(CacheKeyResolver.GetKey(args).ToString(), args.Result);
}
+ public object GetObject(ICacheKey cacheKey)
+ {
+ return InternalGetObject(cacheKey.ToString());
+ }
+
+ public bool ContansObject(ICacheKey cacheKey)
+ {
+ return InternalContansObject(cacheKey.ToString());
+ }
+
+ public void AddObject(ICacheKey cacheKey, object objectForCaching)
+ {
+ InternalAddObject(cacheKey.ToString(), objectForCaching);
+ }
+
public bool ClearCache()
{
return InternalClearCache();
@@ -181,5 +197,11 @@ public bool RemoveFromRelatedCache(string releatedKey)
return InternalRemoveObject(releatedKey);
}
+
+
+ public ICacheKey GetLatestCacheKey(object id)
+ {
+ return _cacheInformation.GetCacheKeys((TIdType)id).Peek();
+ }
}
}
Oops, something went wrong.

0 comments on commit cd0d841

Please sign in to comment.