Example #1
0
        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]));
        }
Example #2
0
 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));
 }
Example #3
0
 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));
 }
Example #4
0
        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));
        }
Example #5
0
        protected void SaveSessionToCache(PassportIdentity identity)
        {
            var key = "SessionToken:" + identity.SessionToken;

            this.Cache[key, CacheDependency.Create(identity.Expiration)] = identity;
        }
Example #6
0
 protected virtual UserGroupRole[] GetCachedUserGroupRoles()
 {
     return(this.PermissionCache.GetObjectFromCache("GetUserGroupRoles", () => this.PermissionDataService.GetUserGroupRoles(), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout))));
 }
Example #7
0
 protected virtual PermissionRelation[] GetCachedPermissionRelations()
 {
     return(this.PermissionCache.GetObjectFromCache("GetPermissionRelations", () => this.PermissionDataService.GetPermissionRelations(), CacheDependency.Create(DateTime.Now.AddSeconds(this.Setting.BufferTimeout))));
 }