void IDnsCache.Set(string key, byte[] bytes, int ttlSeconds)
        {
            CacheItem item = new CacheItem(key, bytes);
            CacheItemPolicy policy = new CacheItemPolicy {AbsoluteExpiration = DateTimeOffset.Now + TimeSpan.FromSeconds(ttlSeconds)};

            _cache.Add(item, policy);
        }
Exemple #2
0
 public LogonResultForm GetUserInfo(string userid)
 {
     var mapper = Common.GetMapperFromSession();
     UserDao userdao = new UserDao(mapper);
     var user = userdao.Query(new UserQueryForm { Name = userid }).FirstOrDefault();
     if (user == null) throw new Exception("用户:" + userid + "在系统中不存在!");
     if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
     LogonResultForm result = new LogonResultForm();
     UserInfoDao userInfoDao = new UserInfoDao(mapper);
     RoleDao roleDao = new RoleDao(mapper);
     LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
     string token = Guid.NewGuid().ToString().Replace("-", "");
     var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
     UserEntireInfo u = new UserEntireInfo { User = user };
     if (userinfo != null) u.UserInfo = userinfo;
     u.Role = roleDao.QueryRoleByUserID(u.User.ID);
     CacheItem item = new CacheItem(token, u);
     LogonHistory history = new LogonHistory
     {
         LogonTime = DateTime.Now,
         Token = token,
         UserID = user.ID,
         ActiveTime = DateTime.Now,
     };
     historyDao.Add(history);
     result.token = token;
     result.UserInfo = userinfo;
     cache.AddItem(item, 30 * 60);
     MenuBLL menubll = new MenuBLL();
     result.Menu = menubll.GetCurrentUserMenu(result.token);
     return result;
 }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="key"></param>
        /// <param name="obj"></param>
        public void Add(string key, object obj)
        {
            var cacheItem = new CacheItem(GeneralKey(key), obj);

            var cacheItemPolicy = new CacheItemPolicy();
            cache.Add(cacheItem, cacheItemPolicy);
        }
Exemple #4
0
		public void AddItem(CacheItem item, double span)
		{
			CacheItemPolicy cp = new CacheItemPolicy();
			cp.SlidingExpiration.Add(TimeSpan.FromMinutes(span));

			cache.Add(item, cp);
		}
        public void Add(TenantInstance instance, Action<string, TenantInstance> removedCallback)
        {
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }

            if (removedCallback == null)
            {
                removedCallback = delegate { };
            }

            // Add a cache entry for the instance id that will be used as a cache dependency
            // for the running instances
            var cacheDependencyPolicy = new CacheItemPolicy
            {
                // Make the "MaxAge" configurable - when the dependency is removed so are the instances
                AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(12)
            };

            var cacheDependency = new CacheItem(instance.Id.ToString(), instance.Id);

            // We need to add the dependency before we set up the instance change monitors,
            // otherwise they'll be removed from the cache immediately!
            cache.Set(instance.Id.ToString(), instance.Id, cacheDependencyPolicy);

            // Now cache the running instance for each identifier
            // The policies must be unique since the RemovedCallback can only be called once-per-policy
            foreach (var id in instance.Tenant.RequestIdentifiers)
            {
                cache.Set(new CacheItem(id, instance), GetCacheItemPolicy(removedCallback, cacheDependency));
            }
        }
Exemple #6
0
 /// <summary>
 /// 向缓存中设置缓存项
 /// </summary>
 /// <param name="key">该缓存项的唯一标识符。</param>
 /// <param name="value">要插入的对象。</param>
 /// <param name="minutesValue">分钟数,精确到最接近的毫秒。一个时段,必须在此时段内访问某个缓存项,否则将从内存中逐出该缓存项。</param>
 /// <param name="removedCallback">在从缓存中移除某个缓存项后将调用该方法。</param>
 public static void Set(string key, object value, double minutesValue, CacheEntryRemovedCallback RemovedCallback)
 {
     CacheItem item = new CacheItem(key, value);
     CacheItemPolicy policy = new CacheItemPolicy();
     policy.SlidingExpiration = TimeSpan.FromMinutes(minutesValue);
     policy.RemovedCallback = RemovedCallback;
     cache.Set(item, policy);
 }
Exemple #7
0
 public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
 {
     var instance = GetCacheItem(item.Key);
     if (instance != null)
         return instance;
     Set(item, policy);
     return item;
 }
 public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     return new CacheItem(item.Key, this.AddOrGetExistingInternal(item.Key, item.Value, policy));
 }
 /// <summary>
 /// Adds principal to cache
 /// </summary>
 /// <param name="principal">principal to add to cache</param>
 public void AddPrincipalToCache(IJumbleblocksPrincipal principal)
 {
     if (principal != null)
     {
         var cacheItem = new CacheItem(principal.Identity.Name, principal);
         Cache.Add(cacheItem, _defaultCachePolicy);
     }
 }
Exemple #10
0
        private static void _SetupMemoryCacheForTest()
        {
            var memoryCache = MemoryCache.Default;

            var fileContents = File.ReadAllText(_contentFilePath);
            var cacheItem = new CacheItem(_contentFilePath, fileContents);
            var cacheItemPolicy = _GetCacheItemPolicy(_contentFilePath);
            memoryCache.Set(cacheItem, cacheItemPolicy);
        }
Exemple #11
0
        /// <summary>
        /// return old entry if it is there.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="policy"></param>
        /// <returns></returns>
        public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
        {
            var old = Get(value.Key, value.RegionName);

            Set(value, policy);
            return old == null
                ? null
                : new CacheItem(value.Key, old, value.RegionName);
        }
        /// <summary>
        /// Inserts a cache entry into the cache without overwriting any existing cache entry.
        /// </summary>
        /// <param name="cacheKey">A unique identifier for the cache entry.</param>
        /// <param name="value">The object to insert.</param>
        /// <param name="cachePolicy">An object that contains eviction details for the cache entry.</param>
        /// <returns>
        ///   <c>true</c> if insertion succeeded, or <c>false</c> if there is an already an entry in the cache that has the same key as key.
        /// </returns>
        public bool Add(CacheKey cacheKey, object value, CachePolicy cachePolicy)
        {
            string key = GetKey(cacheKey);
            var item = new CacheItem(key, value);
            var policy = CreatePolicy(cacheKey, cachePolicy);

            var existing = MemoryCache.Default.AddOrGetExisting(item, policy);
            return existing.Value == null;
        }
Exemple #13
0
        public LoginResultForm Login(string username, string password)
        {
            LoginResultForm result = new LoginResultForm();
            ISqlMapper mapper = MapperHelper.GetMapper();
            UserDao userdao = new UserDao(mapper);
            UserInfoDao userInfoDao = new UserInfoDao(mapper);
            RoleDao roleDao = new RoleDao(mapper);
            User_RoleDao urdao = new User_RoleDao(mapper);
            LogonHistoryDao historyDao = new LogonHistoryDao(mapper);
            MenuDao menudao = new MenuDao(mapper);
            Menu_RoleDao mrdao = new Menu_RoleDao(mapper);
            var user = userdao.Query(new UserQueryForm { Name = username, Password = password }).FirstOrDefault();
            if (user != null)
            {
                if (user.Enabled == 0) throw new Exception("该用户已被禁用,请联系管理员!");
                string token = Guid.NewGuid().ToString().Replace("-", "");
                var userinfo = userInfoDao.Query(new UserInfoQueryForm { ID = user.ID }).FirstOrDefault();
                var ur = urdao.Query(new User_RoleQueryForm { UserID = user.ID });
                List<string> roleidlist = new List<string>();
                ur.ForEach(t =>
                {
                    roleidlist.Add(t.RoleID);
                });
                var roles = roleDao.Query(new RoleQueryForm { IDs = roleidlist });

                var mrs = mrdao.Query(new Menu_RoleQueryForm { RoleIDs = roleidlist });
                var menuids = (from mr in mrs select mr.MenuID).Distinct().ToList();

                result.Menu = menudao.Query(new MenuQueryForm { IDs = menuids, Enabled = 1 });

                UserEntireInfo u = new UserEntireInfo
                {
                    User = user,
                    UserInfo = userinfo,
                    Role = roles,
                };

                CacheItem item = new CacheItem(token, u);
                LogonHistory history = new LogonHistory
                {
                    LogonTime = DateTime.Now,
                    Token = token,
                    UserID = user.ID,
                    ActiveTime = DateTime.Now,
                };
                historyDao.Add(history);
                result.User = u;
                result.token = token;
                cache.AddItem(item, 1800);
                //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "login user:"******",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor);
                return result;
            }
            else
            {
                throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!");
            }
        }
		protected override object OnAddOrGetExisting(string prefixedKey, object value, DateTimeOffset absoluteExpiration)
		{

			var c = new CacheItem(prefixedKey, value);
			var p = new CacheItemPolicy { AbsoluteExpiration = absoluteExpiration, Priority = System.Runtime.Caching.CacheItemPriority.Default };
			var o = _core.AddOrGetExisting(c, p);
			return o.Value;

		}
        /// <summary>
        /// Saves an object to cache memory
        /// Cache will expire after 1 day 
        /// </summary>
        /// <param name="key">Associated Key name</param>
        /// <param name="value">Value to save in cache</param>
        public void SetCache(string key, object value)
        {
            CacheItem cacheItem = new CacheItem(key, value);
            CacheItemPolicy policy = new CacheItemPolicy
            {
                AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddDays(1))
            };

            Cache.Add(cacheItem.Key, cacheItem.Value, policy);
        }
Exemple #16
0
        public void Set(string key, object value, TimeSpan duration)
        {
            var item = new CacheItem(key, value);
            var policy = new CacheItemPolicy()
            {
                AbsoluteExpiration = new DateTimeOffset(DateTime.Now.Add(duration))
            };

            _cache.Set(item, policy);
        }
 public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem) {
     if (source == null) {
         throw new ArgumentNullException("source");
     }
     if (cacheItem == null) {
         throw new ArgumentNullException("cacheItem");
     }
     _source = source;
     _reason = reason;
     _cacheItem = cacheItem;
 }
		public void Set(string key, object value, int? cacheTime)
		{
			var cacheItem = new CacheItem(key, value);
			CacheItemPolicy policy = null;
			if (cacheTime.GetValueOrDefault() > 0)
			{
				policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + TimeSpan.FromMinutes(cacheTime.Value) };
			}

			Cache.Add(cacheItem, policy);
		}
        public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
        {
            var data = this.Get(value.Key, value.RegionName);
            if (data != null)
            {
                return new CacheItem(value.Key, data, value.RegionName);
            }

            this.Set(value, policy);
            return value;
        }
Exemple #20
0
		private void PutRssItemsInCacheAndStorage(string cacheKey, List<RssFeedItem> rssFeedItems)
		{
			var ci = new CacheItem(cacheKey, new {LastDownloadTime = DateTimeOffset.Now, RssFeedItems = rssFeedItems});
			var cip = new CacheItemPolicy
			{
				SlidingExpiration = _configurationService.GetGeneralSettings().RssCacheSlidingExpiration
			};
			_cache.Set(ci, cip);

			_newsStorage.UpdateNews(cacheKey, rssFeedItems);
		}
        public void Add(string id)
        {
            Console.WriteLine("{0} - Add... for '{1}'", typeName, id);

            var cacheItemPolicy = new CacheItemPolicy();

            cacheItemPolicy.AbsoluteExpiration = DateTimeOffset.Now.AddSeconds(5);

            var cacheItem = new CacheItem(id, new CacheData { CacheItemPolicy = cacheItemPolicy });
            store.Add(cacheItem, cacheItemPolicy);
        }
        /// <summary>
        /// Sets the value into the cache using the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <param name="expiry">The expiry.</param>
        public void Set(string key, object value, DateTime? expiry = null)
        {
            CacheItem cacheItem = new CacheItem(key, value);
            CacheItemPolicy policy = null;

            if (expiry.HasValue)
            {
                policy = new CacheItemPolicy() { AbsoluteExpiration = expiry.Value };
            }

            MemoryCache.Default.Add(cacheItem, policy);
        }
        public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
        {
            var item = GetCacheItem(value.Key, value.RegionName);

            if (item == null)
            {
                Set(value, policy);
                item = value;
            }

            return item;
        }
		public CacheEntryRemovedArguments (ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
		{
			if (source == null)
				throw new ArgumentNullException ("source");

			if (cacheItem == null)
				throw new ArgumentNullException ("cacheItem");
			
			this.CacheItem = cacheItem;
			this.RemovedReason = reason;
			this.Source = source;
		}
        public void Set(CacheableEntity cacheItem, SyncMode syncMode = SyncMode.NoSync)
        {
            var item = new CacheItem(cacheItem.GetUniqueHash(), cacheItem);

            if (IsSlaveCache && syncMode != SyncMode.NoSync)
                _masterCache.Set(cacheItem, GetSyncModeForParentCache(syncMode));

            lock (_locker)
                _cacheInfraestructure.Set(item.Key, item, GetDefaultCacheItemPolicy());

            ItemEstablished(cacheItem);
        }
		public void Set(string key, object value, int? cacheTime)
		{
			var cacheItem = new CacheItem(key, value);
			CacheItemPolicy policy = null;
			if (cacheTime.HasValue)
			{
				var span = cacheTime.Value == 0 ? TimeSpan.FromMilliseconds(10) : TimeSpan.FromMinutes(cacheTime.Value);
				policy = new CacheItemPolicy { AbsoluteExpiration = DateTime.Now + span };
			}

			Cache.Add(cacheItem, policy);
		}
        /// <summary>
        /// Saves an object to cache memory
        ///
        /// </summary>
        /// <param name="key">Associated Key name</param>
        /// <param name="value">Value to save in cache</param>
        /// <param name="cacheItemPolicy">Lifetime of cache in seconds</param>
        public void SetCache(string key, object value, int cacheItemPolicy)
        {
            if (key != null && value != null)
            {
                CacheItem cacheItem = new CacheItem(key, value);
                CacheItemPolicy policy = new CacheItemPolicy
                {
                    AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddSeconds(cacheItemPolicy))
                };

                Cache.Add(cacheItem.Key, cacheItem.Value, policy);
            }
        }
Exemple #28
0
		public override CacheItem AddOrGetExisting (CacheItem value, CacheItemPolicy policy)
		{
			MethodCalled = "AddOrGetExisting (CacheItem value, CacheItemPolicy policy)";
			if (value == null)
				return null;

			object item;
			if (Cache.TryGetValue (value.Key, out item))
				return item as CacheItem;

			Cache.Add (value.Key, value);
			return null;
		}
 public OperationResult GetCache(string KeyId)
 {
     if (KeyId != null || KeyId != "")
     {
         item = Mycache.GetCacheItem(KeyId);
         if (item.Equals(null))
         {
             return new OperationResult(OperationResultType.Success, string.Format("成功取得{0}缓存值", KeyId), item.Value);
         }
         return new OperationResult(OperationResultType.QueryNull, string.Format("键{0}的缓存为空", KeyId));
     }
     return new OperationResult(OperationResultType.ParamError, "KeyId is null");
 }
Exemple #30
0
        public CacheItem GetCacheItem(string key, string regionName = null)
        {
            CacheItem cacheItem = new CacheItem(key);
            RedisValue redisValue = RedisDatabase.StringGet(key);

            if (redisValue.IsNullOrEmpty || !redisValue.HasValue)
            {
                return null;
            }

            cacheItem.Value = redisValue;
            return cacheItem;
        }
 public override bool Add(CacheItem item, CacheItemPolicy policy)
 {
     return(Add(item.Key, item.Value, policy, item.RegionName));
 }
Exemple #32
0
 public override CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy)
 {
     Contract.Requires(value != null);
     Contract.Ensures(Contract.Result <CacheItem>() != null);
     throw new NotImplementedException();
 }
Exemple #33
0
 public override void Set(CacheItem item, CacheItemPolicy policy)
 {
     Contract.Requires(item != null);
     throw new NotImplementedException();
 }
Exemple #34
0
 public override System.Runtime.Caching.CacheItem AddOrGetExisting(System.Runtime.Caching.CacheItem value, System.Runtime.Caching.CacheItemPolicy policy)
 {
     throw new NotImplementedException();
 }
 public virtual bool Add(CacheItem item, CacheItemPolicy policy)
 {
     return(AddOrGetExisting(item, policy) == null);
 }
Exemple #36
0
 public override void Set(CacheItem item, CacheItemPolicy policy)
 {
 }
Exemple #37
0
 public Boolean Add(ASP.CacheItem item, ASP.CacheItemPolicy policy)
 {
     return(false);
 }
 public override void Set(CacheItem item, CacheItemPolicy policy)
 {
     Set(item.Key, item.Value, policy, item.RegionName);
 }
        public override CacheItem GetCacheItem(string key, string regionName = null)
        {
            CacheItem temporary = base.GetCacheItem(CreateKeyWithRegion(key, regionName));

            return(new CacheItem(key, temporary.Value, regionName));
        }
 public abstract void Set(CacheItem item, CacheItemPolicy policy);
Exemple #41
0
 public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
 {
     return(default(CacheItem));
 }
Exemple #42
0
        public CacheEntryRemovedArguments(ObjectCache source, CacheEntryRemovedReason reason, CacheItem cacheItem)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            if (cacheItem == null)
            {
                throw new ArgumentNullException("cacheItem");
            }

            this.CacheItem     = cacheItem;
            this.RemovedReason = reason;
            this.Source        = source;
        }
 public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
 {
     return(new CacheItem(CreateKeyWithRegion(item.Key, item.RegionName), base.AddOrGetExisting(CreateKeyWithRegion(item.Key, item.RegionName), item.Value, policy)));
 }
Exemple #44
0
 public virtual new bool Add(CacheItem item, CacheItemPolicy policy)
 {
     return(default(bool));
 }
Exemple #45
0
 public override void Set(System.Runtime.Caching.CacheItem item, System.Runtime.Caching.CacheItemPolicy policy)
 {
     throw new NotImplementedException();
 }
Exemple #46
0
        public override bool Add(CacheItem item, CacheItemPolicy policy)
        {
            CacheItem existingEntry = AddOrGetExisting(item, policy);

            return(existingEntry == null || existingEntry.Value == null);
        }
 public abstract CacheItem AddOrGetExisting(CacheItem value, CacheItemPolicy policy);