Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated the cache disabler
- Loading branch information
gravypower
committed
Jan 17, 2013
1 parent
9e1e2bb
commit cd0d841
Showing
29 changed files
with
501 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
public interface ICacheKey | ||
{ | ||
bool Equals(object other); | ||
object GetId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.