protected IAOPResult <T> GetFromCache <T>(string key, object lockObject, GettingHandler <T> missingHandler) { var timeout = this.Setting.CacheTimeout; if (timeout < 0) //不缓存 { string url = null; try { var item = missingHandler(out url); return(AOPResult.Success(item)); } catch (Exception e) { return(this.ErrorHandle <T>(url, e)); } } if (!this.cache.Contains(key)) { lock (lockObject) { if (!this.cache.Contains(key)) { string url = null; try { var item = missingHandler(out url); if (timeout > 0) { this.cache[key, CacheDependency.Create(TimeSpan.FromSeconds(timeout))] = item; } else { this.cache[key] = item; } } catch (Exception e) { return(this.ErrorHandle <T>(url, e)); } } } } return(AOPResult.Success((T)this.cache[key])); }
private PermissionObject[] GetCachedPermissionsByPermissionNo(string permissionNo) { if (this.Setting.Cached) { return(this.PermissionCache.GetObjectFromCache("GetCachedPermissionsByPermissionNo:" + permissionNo, () => this.PermissionService.GetPermissionsByPermissionNo(permissionNo), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout)))); } return(this.PermissionService.GetPermissionsByPermissionNo(permissionNo)); }
private PermissionResource[] GetCachedPermissionResources() { if (this.Setting.Cached) { return(this.PermissionCache.GetObjectFromCache("GetPermissionResources", () => this.PermissionService.GetPermissionResourcesByAppNo(this.Setting.AppNo), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout)))); } return(this.PermissionService.GetPermissionResourcesByAppNo(this.Setting.AppNo)); }
protected virtual PermissionObject[] GetCachedUserPermissions(string userName) { var mappingName = this.MapUser(userName); if (string.IsNullOrEmpty(mappingName)) { return(null); } if (this.Setting.Cached) { return(this.PermissionCache.GetObjectFromCache("GetUserPermissions:" + mappingName, () => this.GetUserPermissionsFromServer(mappingName, userName), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout)))); } return(this.GetUserPermissionsFromServer(mappingName, userName)); }
protected void SaveSessionToCache(PassportIdentity identity) { var key = "SessionToken:" + identity.SessionToken; this.Cache[key, CacheDependency.Create(identity.Expiration)] = identity; }
protected virtual UserGroupRole[] GetCachedUserGroupRoles() { return(this.PermissionCache.GetObjectFromCache("GetUserGroupRoles", () => this.PermissionDataService.GetUserGroupRoles(), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout)))); }
protected virtual PermissionRelation[] GetCachedPermissionRelations() { return(this.PermissionCache.GetObjectFromCache("GetPermissionRelations", () => this.PermissionDataService.GetPermissionRelations(), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout)))); }