private static IReadOnlyCollection <PermissionType> GetFromCache(UserToken userToken, EntityToken entityToken, object cachingKey) { // Using RequestLifetimeCache and there for no thread locking /MRJ Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > > permissionTypeCache; if (RequestLifetimeCache.HasKey(cachingKey)) { permissionTypeCache = RequestLifetimeCache.TryGet <Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > > >(cachingKey); } else { permissionTypeCache = new Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > >(); RequestLifetimeCache.Add(cachingKey, permissionTypeCache); } Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > entityTokenPermissionTypes; if (!permissionTypeCache.TryGetValue(userToken, out entityTokenPermissionTypes)) { entityTokenPermissionTypes = new Dictionary <EntityToken, IReadOnlyCollection <PermissionType> >(); permissionTypeCache.Add(userToken, entityTokenPermissionTypes); } IReadOnlyCollection <PermissionType> permissionTypes; entityTokenPermissionTypes.TryGetValue(entityToken, out permissionTypes); return(permissionTypes); }
private static void SetToCache(UserToken userToken, EntityToken entityToken, IReadOnlyCollection <PermissionType> permissionTypes, object cachingKey) { // Using RequestLifetimeCache and there for no thread locking /MRJ Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > > permissionTypeCache; if (RequestLifetimeCache.HasKey(cachingKey)) { permissionTypeCache = RequestLifetimeCache.TryGet <Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > > >(cachingKey); } else { permissionTypeCache = new Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > >(); RequestLifetimeCache.Add(cachingKey, permissionTypeCache); } Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > entityTokenPermissionTypes; if (!permissionTypeCache.TryGetValue(userToken, out entityTokenPermissionTypes)) { entityTokenPermissionTypes = new Dictionary <EntityToken, IReadOnlyCollection <PermissionType> >(); permissionTypeCache.Add(userToken, entityTokenPermissionTypes); } if (!entityTokenPermissionTypes.ContainsKey(entityToken)) { entityTokenPermissionTypes.Add(entityToken, permissionTypes); } else { entityTokenPermissionTypes[entityToken] = entityTokenPermissionTypes[entityToken].Concat(permissionTypes).Distinct().ToList(); } }
private static IReadOnlyCollection <PermissionType> GetFromCache(UserToken userToken, EntityToken entityToken, object cachingKey) { var permissionTypeCache = RequestLifetimeCache.TryGet <Dictionary <UserToken, Dictionary <EntityToken, IReadOnlyCollection <PermissionType> > > >(cachingKey); if (permissionTypeCache == null || !permissionTypeCache.TryGetValue(userToken, out var entityTokenPermissionTypes)) { return(null); } entityTokenPermissionTypes.TryGetValue(entityToken, out var permissionTypes); return(permissionTypes); }
private IUserDeveloperSettings GetDeveloperSettings() { if (RequestLifetimeCache.HasKey(typeof(IUserDeveloperSettings))) { return(RequestLifetimeCache.TryGet <IUserDeveloperSettings>(typeof(IUserDeveloperSettings))); } IUserDeveloperSettings settings = DataFacade.GetData <IUserDeveloperSettings>(f => f.Username == UserSettings.Username).FirstOrDefault(); if (settings == null) { settings = CreateUserDeveloperSettings(); } RequestLifetimeCache.Add(typeof(IUserDeveloperSettings), settings); return(settings); }
/// <exclude /> public static CultureInfo GetCurrentActiveLocaleCultureInfo(string username) { var key = "CurrentActiveCulture" + username; if (RequestLifetimeCache.HasKey(key)) { return(RequestLifetimeCache.TryGet <CultureInfo>(key)); } var cultureInfo = _implementation.GetCurrentActiveLocaleCultureInfo(username); var allowedCultures = GetActiveLocaleCultureInfos(username, true); if (!allowedCultures.Contains(cultureInfo)) { cultureInfo = allowedCultures.FirstOrDefault(); } if (cultureInfo != null && !RequestLifetimeCache.HasKey(key)) { RequestLifetimeCache.Add(key, cultureInfo); } return(cultureInfo ?? CultureInfo.InvariantCulture); }