• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Caching.CacheItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Runtime.Caching.CacheItem的典型用法代码示例。如果您正苦于以下问题:C# CacheItem类的具体用法?C# CacheItem怎么用?C# CacheItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CacheItem类属于System.Runtime.Caching命名空间,在下文中一共展示了CacheItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetUserInfo

 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;
 }
开发者ID:franknew,项目名称:RiskMgr,代码行数:32,代码来源:LogonBLL.cs


示例2: CacheItem

        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);
        }
开发者ID:CedarLogic,项目名称:csharp-dns-server,代码行数:7,代码来源:DnsCache.cs


示例3: Add

        /// <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);
        }
开发者ID:wudan330260402,项目名称:Danwu.Core,代码行数:12,代码来源:LocalCacheStorage.cs


示例4: AddItem

		public void AddItem(CacheItem item, double span)
		{
			CacheItemPolicy cp = new CacheItemPolicy();
			cp.SlidingExpiration.Add(TimeSpan.FromMinutes(span));

			cache.Add(item, cp);
		}
开发者ID:jlacube,项目名称:Generic.Caching,代码行数:7,代码来源:Program.cs


示例5: Add

        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));
            }
        }
开发者ID:nicolocodev,项目名称:saaskit,代码行数:33,代码来源:MemoryCacheInstanceStore.cs


示例6: AddOrGetExisting

 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));
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:MemoryCache.cs


示例7: AddPrincipalToCache

 /// <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);
     }
 }
开发者ID:AndyCC,项目名称:Jumbleblocks-website,代码行数:12,代码来源:MemoryUserCache.cs


示例8: AddOrGetExisting

 public override CacheItem AddOrGetExisting(CacheItem item, CacheItemPolicy policy)
 {
     var instance = GetCacheItem(item.Key);
     if (instance != null)
         return instance;
     Set(item, policy);
     return item;
 }
开发者ID:patrickhuber,项目名称:CacheIt,代码行数:8,代码来源:RedisCache.cs


示例9: Set

 /// <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);
 }
开发者ID:Qlinzpc,项目名称:Qizero4.5,代码行数:15,代码来源:MCache.cs


示例10: Login

        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:" + username + ",token:" + token }, SOAFramework.Library.CacheEnum.FormMonitor);
                return result;
            }
            else
            {
                throw new Exception("用户名或者密码错误!请输入正确的用户名和密码!");
            }
        }
开发者ID:franknew,项目名称:AnjuManager,代码行数:57,代码来源:LoginBLL.cs


示例11: AddOrGetExisting

        /// <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);
        }
开发者ID:LHCAtlas,项目名称:AtlasSSH,代码行数:15,代码来源:DiskCache.cs


示例12: Add

        /// <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;
        }
开发者ID:vas6ili,项目名称:EntityFramework.Extended,代码行数:18,代码来源:MemoryCacheProvider.cs


示例13: OnAddOrGetExisting

		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;

		}
开发者ID:waynebaby,项目名称:D.E.A.D.,代码行数:9,代码来源:ObjectCacheBasedCacheDictionaryBase.cs


示例14: _SetupMemoryCacheForTest

        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);
        }
开发者ID:nchetan,项目名称:poc,代码行数:9,代码来源:Program.cs


示例15: Set

        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);
        }
开发者ID:w-g,项目名称:sediment,代码行数:10,代码来源:MemoryCacheWrapper.cs


示例16: SetCache

        /// <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);
        }
开发者ID:mp222sf,项目名称:jamforelsetjanst,代码行数:16,代码来源:CacheManager.cs


示例17: Set

		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);
		}
开发者ID:GloriousOnion,项目名称:SmartStoreNET,代码行数:11,代码来源:StaticCache.cs


示例18: CacheEntryRemovedArguments

 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;
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:CacheEntryRemovedArguments.cs


示例19: Add

        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);
        }
开发者ID:MSDEVMTL,项目名称:2015-11-10-Event-based-Asynchronous-Pattern,代码行数:11,代码来源:Program.cs


示例20: PutRssItemsInCacheAndStorage

		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);
		}
开发者ID:evkap,项目名称:MetaPortal,代码行数:11,代码来源:RssParserService.cs



注:本文中的System.Runtime.Caching.CacheItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Caching.CacheItemPolicy类代码示例发布时间:2022-05-26
下一篇:
C# Runtime.TimeoutHelper类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap