#20476: Adding CacheAuthenticatedRequests setting.

Work Item: 20476
This commit is contained in:
Brett Morrison
2014-10-20 17:10:52 -07:00
committed by Sipke Schoorstra
parent c1e29b75a7
commit 245a296c3f
5 changed files with 27 additions and 7 deletions
@@ -90,7 +90,8 @@ namespace Orchard.OutputCache.Controllers {
DebugMode = settings.DebugMode,
ApplyCulture = settings.ApplyCulture,
RouteConfigurations = routeConfigurations,
IgnoreNoCache = settings.IgnoreNoCache
IgnoreNoCache = settings.IgnoreNoCache,
CacheAuthenticatedRequests = settings.CacheAuthenticatedRequests
};
return View(model);
@@ -115,10 +116,10 @@ namespace Orchard.OutputCache.Controllers {
settings.DebugMode = model.DebugMode;
settings.ApplyCulture = model.ApplyCulture;
settings.IgnoreNoCache = model.IgnoreNoCache;
settings.CacheAuthenticatedRequests = model.CacheAuthenticatedRequests;
// invalidates the settings cache
_signals.Trigger(CacheSettingsPart.CacheKey);
_cacheService.SaveCacheConfigurations(model.RouteConfigurations);
Services.Notifier.Information(T("Cache Settings saved successfully."));
@@ -88,6 +88,7 @@ namespace Orchard.OutputCache.Filters {
private string[] _varyQueryStringParameters;
private ISet<string> _varyRequestHeaders;
private bool _transformRedirect;
private bool _cacheAuthenticatedRequests;
private WorkContext _workContext;
private CacheItem _cacheItem;
@@ -137,13 +138,18 @@ namespace Orchard.OutputCache.Filters {
return;
}
// don't return any cached content, or cache any content, if the user is authenticated
if (_workContext.CurrentUser != null) {
// cache if authenticated setting
_cacheAuthenticatedRequests = _cacheManager.Get("CacheSettingsPart.CacheAuthenticatedRequests", context => {
context.Monitor(_signals.When(CacheSettingsPart.CacheKey));
return _workContext.CurrentSite.As<CacheSettingsPart>().CacheAuthenticatedRequests;
});
// don't return any cached content, or cache any content, if the user is authenticated, unless the setting "cache authenticated requests" is true
if (_workContext.CurrentUser != null && !_cacheAuthenticatedRequests) {
Logger.Debug("Request ignored on Authenticated user");
return;
}
// caches the default cache duration to prevent a query to the settings
_cacheDuration = _cacheManager.Get("CacheSettingsPart.Duration",
context => {
@@ -43,5 +43,10 @@ namespace Orchard.OutputCache.Models {
get { return this.Retrieve(x => x.IgnoreNoCache); }
set { this.Store(x => x.IgnoreNoCache, value); }
}
public bool CacheAuthenticatedRequests {
get { return this.Retrieve(x => x.CacheAuthenticatedRequests); }
set { this.Store(x => x.CacheAuthenticatedRequests, value); }
}
}
}
@@ -14,5 +14,6 @@ namespace Orchard.OutputCache.ViewModels {
public string VaryQueryStringParameters { get; set; }
public string VaryRequestHeaders { get; set; }
public bool IgnoreNoCache { get; set; }
public bool CacheAuthenticatedRequests { get; set; }
}
}
@@ -54,8 +54,15 @@
<label>@T("Culture")</label>
@Html.CheckBoxFor(m => m.ApplyCulture) <label for="@Html.FieldIdFor(m => m.ApplyCulture)" class="forcheckbox">@T("Differentiate cultures")</label>
<span class="hint">@T("When checked, the cached content will differ per culture too. For better performance, leave this unchecked if your website uses only one culture.")</span>
</fieldset>
</fieldset>
<fieldset>
<label>@T("Authenticated Requests")</label>
@Html.CheckBoxFor(m => m.CacheAuthenticatedRequests)
<label for="@Html.FieldIdFor(m => m.CacheAuthenticatedRequests)" class="forcheckbox">@T("Cache Authenticated Requests")</label>
@Html.Hint(T("When checked, the output cache filter will store the HTML output to cache and retrieve from cache even if the user is authenticated. When unchecked, it will bypass cache for authenticated users."))
</fieldset>
<fieldset>
<label>@T("Debug mode")</label>
@Html.CheckBoxFor(m => m.DebugMode) <label for="@Html.FieldIdFor(m => m.DebugMode)" class="forcheckbox">@T("Render caching information in cached pages")</label>