Open orchardbot opened 9 years ago
@jeffolmstead commented:
I actually do something like this in my Navigator Cache module to allow me to cache against authenticated users. However, I would like to mention the possibility that you cache against the roles rather than the user as it will cut down the amount of cached content. I know on some sites you will want it per user (so maybe that should be a setting) but it would get overwhelming. Caching by the roles the user is in creates far less overhead.
@sebastienros commented:
If a user is in two roles, I assume we would then have a third cache key. So the cache key would actually be for any distinct set of roles. Agreed? That could then be another option on top of user based. Same restrictions though that the cached pages should not leak any personal information.
@jeffolmstead commented:
Yes, I agree about the cache key being for a distinct set of roles. Here is the code block I use in Rework. Navigator Cache module: https://navigationcache.codeplex.com/
var user = _workContextAccessor.GetContext().CurrentUser;
if (user != null) {
cacheKey = String.Format("{0}_{1}", cacheKey, "authenticated");
var currentUserRoleRecords = _userRolesRepository.Fetch(x => x.UserId == user.Id);
foreach (var userRoleRecord in currentUserRoleRecords.OrderBy(urr => urr.Role.Name)) {
cacheKey = String.Format("{0}_{1}", cacheKey, userRoleRecord.Role.Id);
}
}
else {
cacheKey = String.Format("{0}_{1}", cacheKey, "anonymous");
}
Look forward to seeing where this ends up.
veskok created: https://orchard.codeplex.com/workitem/21061
In the next release when computing cache key and cache is enabled for authenticated users, cachke key must include user name, that means the cache must be per authenticated user if caching authenticated requests.