Exemplo n.º 1
0
        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        public IList <VWProductBaoPinEntity> GetProductBaoPinList(int pageIndex, int pageSize, ref int recordCount, int isactive, int showproduct)
        {
            IList <VWProductBaoPinEntity> list = null;
            string _cachekey    = "GetProductBaoPinList_" + pageIndex + "_" + pageSize + "_" + isactive + showproduct;
            string _cachekeynum = "GetProductBaoPinListNum_" + pageIndex + "_" + pageSize + "_" + isactive + showproduct;
            object obj          = MemCache.GetCache(_cachekey);

            if (obj == null)
            {
                list = ProductBaoPinDA.Instance.GetProductBaoPinList(pageSize, pageIndex, ref recordCount, isactive, showproduct);
                foreach (VWProductBaoPinEntity entity in list)
                {
                    if (entity.ProductDetailId > 0)
                    {
                        entity.ProductDetail = ProductBLL.Instance.GetProVWByDetailId(entity.ProductDetailId);
                        entity.ProductId     = entity.ProductDetail.ProductId;
                        if (entity.ProductDetail.BrandId > 0)
                        {
                            entity.Brand = BrandBLL.Instance.GetBrand(entity.ProductDetail.BrandId);
                        }
                    }
                }
                MemCache.AddCache(_cachekey, list);
                MemCache.AddCache(_cachekeynum, recordCount);
            }
            else
            {
                list        = (IList <VWProductBaoPinEntity>)obj;
                recordCount = StringUtils.GetDbInt(MemCache.GetCache(_cachekeynum));
            }
            return(list);
        }
Exemplo n.º 2
0
 public MyCached()
 {
     this.listener          = new TcpListener(IPAddress.Any, Configuration.ListenPort);
     this.clientConnections = new Dictionary <IPEndPoint, TcpConnection>();
     this.cache             = new MemCache();
     this.queuedResponses   = new Queue <byte[]>();
 }
Exemplo n.º 3
0
        public ActionResult ClearMemCache()
        {
            string _cachekey = QueryString.SafeQ("id");

            MemCache.RemoveAllCache();
            return(View());
        }
Exemplo n.º 4
0
        public IList <CarTypeModelEntity> GetCarTypeModelAll(int seriesid, bool cache = false)
        {
            IList <CarTypeModelEntity> list = null;

            if (cache)
            {
                string _cachekey = "GetCarTypeModelAll_" + seriesid;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    list = CarTypeModelDA.Instance.GetCarTypeModelAll(seriesid);
                    MemCache.AddCache(_cachekey, list);
                }
                else
                {
                    list = (IList <CarTypeModelEntity>)obj;
                }
            }
            else
            {
                list = CarTypeModelDA.Instance.GetCarTypeModelAll(seriesid);
            }

            return(list);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 仅仅获取分类
        /// </summary>
        /// <param name="siteid"></param>
        /// <param name="classnenutype"></param>
        /// <param name="parentid"></param>
        /// <param name="iscache"></param>
        /// <returns></returns>
        public IList <VWClassesFoundEntity> GetClassFoundAll(int siteid, int parentid, bool iscache = false)
        {
            IList <VWClassesFoundEntity> list = new List <VWClassesFoundEntity>();

            if (iscache == false)
            {
                string _cachekey = "GetClassFoundAll_" + siteid + "_" + parentid;
                object obj       = MemCache.GetCache(_cachekey);

                if (obj == null)
                {
                    list = ClassesFoundDA.Instance.GetClassMenuAll(siteid, parentid);

                    MemCache.AddCache(_cachekey, list);
                }
                else
                {
                    list = (IList <VWClassesFoundEntity>)obj;
                }
            }
            else
            {
                list = ClassesFoundDA.Instance.GetClassMenuAll(siteid, parentid);
            }
            return(list);
        }
Exemplo n.º 6
0
 public IList <ClassesFoundEntity> GetClassesAllByBrandId(int siteid, int brandid, bool iscache)
 {
     if (iscache == false)
     {
         string _cachekey = "GetClassesAllByBrandId_" + siteid + "_" + brandid;
         object obj       = MemCache.GetCache(_cachekey);
         IList <ClassesFoundEntity> list = null;
         if (obj == null)
         {
             list = ClassesFoundDA.Instance.GetClassesAllByBrandId(siteid, brandid);
             MemCache.AddCache(_cachekey, list);
         }
         else
         {
             list = (IList <ClassesFoundEntity>)obj;
         }
         return(list);
     }
     else
     {
         IList <ClassesFoundEntity> list = null;
         list = ClassesFoundDA.Instance.GetClassesAllByBrandId(siteid, brandid);
         return(list);
     }
 }
Exemplo n.º 7
0
 /// <summary>
 /// 根据主键获取一个ClassesFound实体记录。
 /// 该方法提供给其他实体的业务逻辑层(Logic)方法调用
 /// </summary>
 /// <returns>ClassesFound实体</returns>
 /// <param name="columns">要返回的列</param>
 public ClassesFoundEntity GetClassesFound(int id, bool iscache = false)
 {
     if (iscache)
     {
         string             _cachekey = "ClassesFound_" + id.ToString();// SysCacheKey.ClassesFoundListKey;
         object             _objcache = MemCache.GetCache(_cachekey);
         ClassesFoundEntity _obj      = new ClassesFoundEntity();
         if (_objcache == null)
         {
             _obj = ClassesFoundDA.Instance.GetClassesFound(id);
             MemCache.AddCache(_cachekey, _obj);
         }
         else
         {
             _obj = (ClassesFoundEntity)_objcache;
         }
         return(_obj);
     }
     else if (iscache == false)
     {
         return(ClassesFoundDA.Instance.GetClassesFound(id));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 8
0
        public List <int> GetSubClassEndList(int classid, bool cache = false)
        {
            List <int> _listint = new List <int>();

            if (cache == false)
            {
                ClassesFoundEntity _entity = GetClassesFound(classid, cache);
                int redirectclassid        = _entity.RedirectClassId;
                if (redirectclassid == 0)
                {
                    redirectclassid = _entity.Id;
                }
                _listint.Add(redirectclassid);
                if (_entity.IsEnd == 0 && redirectclassid > 0)
                {
                    IList <ClassesFoundEntity> _entitylist2 = GetClassesAllByPId(redirectclassid, cache, -1);
                    if (_entitylist2 != null && _entitylist2.Count > 0)
                    {
                        foreach (ClassesFoundEntity _entity2 in _entitylist2)
                        {
                            List <int> listsub = GetSubClassEndList(_entity2.Id, cache);
                            _listint.AddRange(listsub);
                        }
                    }
                }
            }
            else
            {
                string _cachekey = "GetSubClassEndList_" + classid;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    ClassesFoundEntity _entity = GetClassesFound(classid, false);
                    int redirectclassid        = _entity.RedirectClassId;
                    if (redirectclassid == 0)
                    {
                        redirectclassid = _entity.Id;
                    }
                    _listint.Add(redirectclassid);
                    if (_entity.IsEnd == 0 && redirectclassid > 0)
                    {
                        IList <ClassesFoundEntity> _entitylist2 = GetClassesAllByPId(redirectclassid, false, -1);
                        if (_entitylist2 != null && _entitylist2.Count > 0)
                        {
                            foreach (ClassesFoundEntity _entity2 in _entitylist2)
                            {
                                List <int> listsub = GetSubClassEndList(_entity2.Id);
                                _listint.AddRange(listsub);
                            }
                        }
                    }
                }
                else
                {
                    _listint = (List <int>)obj;
                }
            }

            return(_listint);
        }
Exemplo n.º 9
0
 public bool Delete(int AISTrackId)
 {
     try
     {
         using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
         {
             var AISTrackExisting = aisTrackRepo.Get <AISTrack>(AISTrackId);
             if (AISTrackExisting == null)
             {
                 return(false);
             }
             else
             {
                 aisTrackRepo.Delete <AISTrack>(AISTrackId);
                 if (MemCache.IsIncache("AllAISTracksKey"))
                 {
                     MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey").Remove(AISTrackExisting);
                 }
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 10
0
        public bool Update(AISTrack AISTrackModel)
        {
            try
            {
                using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
                {
                    if (MemCache.IsIncache("AllAISTracksKey"))
                    {
                        List <AISTrack> aISTracks = MemCache.GetFromCache <List <AISTrack> >("AllStakeholdersKey");
                        if (aISTracks.Count > 0)
                        {
                            aISTracks.Remove(aISTracks.Find(x => x.AISTrackId == AISTrackModel.AISTrackId));
                        }
                    }

                    aisTrackRepo.Update <AISTrack>(AISTrackModel);
                    if (MemCache.IsIncache("AllStakeholdersKey"))
                    {
                        MemCache.GetFromCache <List <AISTrack> >("AllStakeholdersKey").Add(AISTrackModel);
                    }
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 11
0
 public AISTrack Add(AISTrack AISTrackModel)
 {
     try
     {
         using (AISTrackRepository aisTrackRepo = new AISTrackRepository())
         {
             // Validate and Map data over here
             if (AISTrackModel != null)
             {
                 var rowId = aisTrackRepo.Insert <AISTrack>(AISTrackModel);
                 AISTrackModel.AISTrackId = rowId;
             }
             if (MemCache.IsIncache("AllAISTracksKey"))
             {
                 MemCache.GetFromCache <List <AISTrack> >("AllAISTracksKey").Add(AISTrackModel);
             }
             else
             {
                 List <AISTrack> tracks = new List <AISTrack>();
                 tracks.Add(AISTrackModel);
                 MemCache.AddToCache("AllAISTracksKey", tracks);
             }
             return(AISTrackModel);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 12
0
 /// <summary>
 /// 根据主键获取一个Brand实体记录。
 /// 该方法提供给其他实体的业务逻辑层(Logic)方法调用
 /// </summary>
 /// <returns>Brand实体</returns>
 /// <param name="columns">要返回的列</param>
 public BrandEntity GetBrand(int id, bool iscache = false)
 {
     if (iscache)
     {
         string      _cachekey = "Brand_" + id.ToString();
         object      _objcache = MemCache.GetCache(_cachekey);
         BrandEntity _obj      = new BrandEntity();
         if (_objcache == null)
         {
             _obj = BrandDA.Instance.GetBrand(id);
             MemCache.AddCache(_cachekey, _obj);
         }
         else
         {
             _obj = (BrandEntity)_objcache;
         }
         return(_obj);
     }
     else if (iscache == false)
     {
         return(BrandDA.Instance.GetBrand(id));
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 13
0
        public VWShowStoreEntity GetNextStore(int preid)
        {
            VWShowStoreEntity entity = new VWShowStoreEntity();

            if (preid > 0)
            {
                string _cachekey = "GetNextStore_" + preid;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    entity = MemStoreDA.Instance.GetNextStore(preid);
                    MemCache.AddCache(_cachekey, entity);
                }
                else
                {
                    entity = (VWShowStoreEntity)obj;
                }
            }
            else
            {
                entity = MemStoreDA.Instance.GetNextStore(preid);
            }

            return(entity);
        }
Exemplo n.º 14
0
        public static UserInfo GetUser(string upn, bool clearCache = false)
        {
            if (clearCache)
            {
                MemCache.Clear(upn);
            }

            var result = (UserInfo)MemCache.Get(upn);

            if (result == null)
            {
                using (var ctx = new ClientContext(SharePointHelper.Url))
                {
                    var u = ctx.Web.EnsureUser(upn);

                    ctx.Load(u);
                    ctx.Load(u.Groups);
                    ctx.ExecuteQuery();

                    result = MapToModel(u);
                    MemCache.Add(upn, result);
                }
            }

            return(result);
        }
Exemplo n.º 15
0
        public ActionResult Ladder()
        {
            var ret = MemCache.GetCached("pwLadder",
                                         () =>
            {
                ZkDataContext db      = new ZkDataContext();
                var gal               = db.Galaxies.First(x => x.IsDefault);
                DateTime minDate      = gal.Started ?? DateTime.UtcNow;
                List <PwLadder> items = db.Accounts.Where(x => x.FactionID != null && x.LastLogin > minDate && x.SpringBattlePlayers.Any(y => y.SpringBattle.StartTime > minDate && !y.IsSpectator && y.SpringBattle.Mode == AutohostMode.Planetwars)).ToList().GroupBy(x => x.Faction)
                                        .Select(
                    x =>
                    new PwLadder
                {
                    Faction = x.Key,
                    Top10   =
                        x.OrderByDescending(y => y.PwAttackPoints)
                        .ThenByDescending(y => y.AccountRatings.Where(r => r.RatingCategory == RatingCategory.Planetwars).Select(r => r.LadderElo).DefaultIfEmpty(WholeHistoryRating.DefaultRating.RealElo).FirstOrDefault())
                        .Take(10)
                        .ToList()
                })
                                        .ToList();
                return(items);
            },
                                         60 * 2);

            return(View("Ladder", ret));
        }
Exemplo n.º 16
0
        public IList <InquiryProductEntity> GetInquiryProductAll(string ordercode, bool cache = false)
        {
            IList <InquiryProductEntity> list = null;

            if (cache)
            {
                string _cachekey = "GetInquiryProductAll" + ordercode;// SysCacheKey.InquiryProductSubListKey;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    list = InquiryProductDA.Instance.GetInquiryProductAll(ordercode);
                    MemCache.AddCache(_cachekey, list);
                }
                else
                {
                    list = (IList <InquiryProductEntity>)obj;
                }
            }
            else
            {
                list = InquiryProductDA.Instance.GetInquiryProductAll(ordercode);
            }

            return(list);
        }
Exemplo n.º 17
0
        public IList <VWTreeCTSeriesEntity> GetTreeCTSeriesBySubBrand(int subbrandid)
        {
            IList <VWTreeCTSeriesEntity> resultlist = new List <VWTreeCTSeriesEntity>();
            string _cachekey = "GetTreeCTSeriesBySubBrand_" + subbrandid;
            object obj       = MemCache.GetCache(_cachekey);

            if (obj == null)
            {
                IList <CarTypeBrandEntity> list        = new List <CarTypeBrandEntity>();
                CarTypeBrandEntity         brandentity = CarTypeBrandDA.Instance.GetCarTypeBrand(subbrandid);
                if (brandentity != null && brandentity.Id > 0)
                {
                    list.Add(brandentity);
                }
                if (list != null && list.Count > 0)
                {
                    foreach (CarTypeBrandEntity entity in list)
                    {
                        IList <CarTypeSeriesEntity> seri      = CarTypeSeriesBLL.Instance.GetCarTypeSeriesAll(-1, entity.Id);
                        VWTreeCTSeriesEntity        addentity = new VWTreeCTSeriesEntity();
                        addentity.Name     = entity.BrandName;
                        addentity.Children = seri;
                        resultlist.Add(addentity);
                    }
                    MemCache.AddCache(_cachekey, resultlist);
                }
            }
            else
            {
                resultlist = (IList <VWTreeCTSeriesEntity>)obj;
            }
            return(resultlist);
        }
Exemplo n.º 18
0
        /// <summary>
        /// 根据主键获取一个DicUnitEnum实体记录。
        /// 该方法提供给其他实体的业务逻辑层(Logic)方法调用
        /// </summary>
        /// <returns>DicUnitEnum实体</returns>
        /// <param name="columns">要返回的列</param>
        public DicUnitEnumEntity GetDicUnitEnum(int id, bool iscache = false)
        {
            DicUnitEnumEntity entity = new DicUnitEnumEntity();

            if (!iscache)
            {
                entity = DicUnitEnumDA.Instance.GetDicUnitEnum(id);
            }
            else
            {
                string _cachekey = "GetDicUnitEnum" + id;// SysCacheKey.DicUnitEnumListKey;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    entity = DicUnitEnumDA.Instance.GetDicUnitEnum(id);
                    MemCache.AddCache(_cachekey, entity);
                }
                else
                {
                    entity = (DicUnitEnumEntity)obj;
                }
            }

            return(entity);
        }
Exemplo n.º 19
0
        public async Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken)
        {
            try
            {
                var actionAuthentication = context.ActionContext.ActionDescriptor.GetCustomAttributes <AuthenticationAttribute>();
                //验证
                if (
                    (actionAuthentication.Count > 0 && actionAuthentication.Last().Authenticate == true) ||
                    (actionAuthentication.Count == 0 && AuthenticationConfig.GetAuthenticateNoAttribute() == true)
                    )
                {
                    var ticket = context.Request.Headers.GetValues(AuthenticationConfig.AuthenticationString).FirstOrDefault();
                    if (ticket == null)
                    {
                        throw new AuthenticationException("can not get  ticket !");
                    }
                    object obj = MemCache.Get(AuthenticationConfig.TicketKeyPrefix + ticket);
                    if (obj == null)
                    {
                        AuthorizationConfig.RemoveRoles(ticket);
                        throw new AuthenticationException("Ticket has Expired !");
                    }

                    if (AuthenticationConfig.GetRefreshTicket())
                    {
                        MemCache.Add(AuthenticationConfig.TicketKeyPrefix + ticket, obj, DateTime.Now.AddSeconds(AuthenticationConfig.GetTicketExpire()));
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 20
0
        public List <Issue> GetIssues()
        {
            using (MiniProfiler.Current.Step(nameof(GetIssues)))
            {
                return(MemCache.GetSet <List <Issue> >("IssuesList", (_, __) =>
                {
                    var result = new List <Issue>();
                    Parallel.ForEach(IssueProviders, p =>
                    {
                        List <Issue> pIssues;
                        using (MiniProfiler.Current.Step("Issues: " + p.Name))
                        {
                            pIssues = p.GetIssues().ToList();
                        }
                        lock (result)
                        {
                            result.AddRange(pIssues);
                        }
                    });

                    return result
                    .OrderByDescending(i => i.IsCluster)
                    .ThenByDescending(i => i.MonitorStatus)
                    .ThenByDescending(i => i.Date)
                    .ThenBy(i => i.Title)
                    .ToList();
                }, 15.Seconds(), 4.Hours()));
            }
        }
Exemplo n.º 21
0
 public void If_I_Try_To_Add_A_Null_Item_To_Cache_It_Must_Throws_Exception()
 {
     string key = "justanotherkey";
     //
     ICache cache = new MemCache();
     cache.Add<string>(null, key);
 }
        /// <summary>
        /// 广告位显示专区数据获取
        /// </summary>
        /// <param name="specialid"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public IList <VWProductSpecialDetailsEntity> GetSpecialDetailsForMenuAD(int specialid, int num = 8)
        {
            IList <VWProductSpecialDetailsEntity> list = null;
            string _cachekey = "GetSpecialDetailsForMenuAD_" + specialid + "_" + num;
            object obj       = MemCache.GetCache(_cachekey);

            if (obj == null)
            {
                list = ProductSpecialDetailsDA.Instance.GetSpecialDetailsForMenuAD(specialid, num);
                if (list != null && list.Count > 0)
                {
                    foreach (VWProductSpecialDetailsEntity entity in list)
                    {
                        entity.ProductDetail = ProductBLL.Instance.GetProVWByDetailId(entity.ProductDetailId);
                    }
                }
                MemCache.AddCache(_cachekey, list);
            }
            else
            {
                list = (IList <VWProductSpecialDetailsEntity>)obj;
            }

            return(list);
        }
Exemplo n.º 23
0
        public string   GetNickNameByMemId(int memid, bool iscache = false)
        {
            string nickname = "";

            if (iscache)
            {
                string _cachekey = "GetNickNameByMemId" + memid;// SysCacheKey.MemberInfoListKey;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    MemberInfoEntity entity = null;
                    entity   = MemberInfoDA.Instance.GetMemberInfoByMemId(memid);
                    nickname = entity.Nickname;
                    MemCache.AddCache(_cachekey, nickname);
                }
                else
                {
                    nickname = obj.ToString();
                }
            }
            else
            {
                MemberInfoEntity entity = null;
                entity   = MemberInfoDA.Instance.GetMemberInfoByMemId(memid);
                nickname = entity.Nickname;
            }

            return(nickname);
        }
        ///// <summary>
        ///// 获得数据列表
        ///// </summary>
        public IList <VWProductSpecialDetailsEntity> GetProductSpecialDetailsList(int pageIndex, int pageSize, ref int recordCount, int specialid, int isactive)
        {
            IList <VWProductSpecialDetailsEntity> list = null;
            string _cachekey    = "GetProductSpecialDetailsList_" + pageIndex + "_" + pageSize + "_" + specialid + "_" + isactive;
            string _cachekeynum = "GetProductSpecialDetailsListNum_" + pageIndex + "_" + pageSize + "_" + specialid + "_" + isactive;
            object obj          = MemCache.GetCache(_cachekey);

            if (obj == null)
            {
                list = ProductSpecialDetailsDA.Instance.GetProductSpecialDetailsList(pageIndex, pageSize, ref recordCount, specialid, isactive);
                if (list != null && list.Count > 0)
                {
                    foreach (VWProductSpecialDetailsEntity entity in list)
                    {
                        entity.ProductDetail = ProductBLL.Instance.GetProVWByDetailId(entity.ProductDetailId);
                    }
                }
                MemCache.AddCache(_cachekey, list);
                MemCache.AddCache(_cachekeynum, recordCount);
            }
            else
            {
                list        = (IList <VWProductSpecialDetailsEntity>)obj;
                recordCount = StringUtils.GetDbInt(MemCache.GetCache(_cachekeynum));
            }

            return(list);
        }
Exemplo n.º 25
0
        /// </summary>
        /// <returns>Store实体</returns>
        /// <param name="columns">要返回的列</param>
        public MemStoreEntity GetStoreByMemId(int memid, bool cache = false)
        {
            MemStoreEntity entity = new MemStoreEntity();

            if (cache)
            {
                string _cachekey = "GetStoreByMemId_" + memid;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    entity = MemStoreDA.Instance.GetStoreByMemId(memid);
                    MemCache.AddCache(_cachekey, entity);
                }
                else
                {
                    entity = (MemStoreEntity)obj;
                }
            }
            else
            {
                entity = MemStoreDA.Instance.GetStoreByMemId(memid);
            }

            return(entity);
        }
Exemplo n.º 26
0
        /// <summary>
        /// Polls all caches on a specific PollNode
        /// </summary>
        /// <param name="nodeType">Type of node to poll</param>
        /// <param name="key">Unique key of the node to poll</param>
        /// <param name="cacheGuid">If included, the specific cache to poll</param>
        /// <returns>Whether the poll was successful</returns>
        public async Task <bool> PollAsync(string nodeType, string key, Guid?cacheGuid = null)
        {
            if (nodeType == Cache.TimedCacheKey)
            {
                MemCache.Remove(key);
                return(true);
            }

            var node = AllPollNodes.FirstOrDefault(p => p.NodeType == nodeType && p.UniqueKey == key);

            if (node == null)
            {
                return(false);
            }

            if (cacheGuid.HasValue)
            {
                var cache = node.DataPollers.FirstOrDefault(p => p.UniqueId == cacheGuid);
                if (cache != null)
                {
                    await cache.PollGenericAsync(true);
                }
                return(cache?.LastPollSuccessful ?? false);
            }
            // Polling an entire server
            await node.PollAsync(true);

            return(true);
        }
Exemplo n.º 27
0
        public void TestGetCorrentCacheValue()
        {
            ICache cache = new MemCache();
            string text  = cache.GetOrSet("text", () => "hello world", 1);

            Assert.AreEqual("hello world", text);
        }
Exemplo n.º 28
0
 public void If_I_Try_To_Add_An_Item_With_Null_Key_It_Must_Throws_Exception()
 {
     string itemInCache = "The quick brown fox jumps over the lazy dog";
     //
     ICache cache = new MemCache();
     cache.Add<string>(itemInCache, null);
 }
Exemplo n.º 29
0
        public void Setup()
        {
            _testScheduler = new TestScheduler();
            IMemCache cache = new MemCache(capacity: 100);

            _requestDispatcher = new RequestDispatcher(_testScheduler, cache, Service.Service.GetRequestHandlers(_testScheduler, cache));
        }
Exemplo n.º 30
0
        public IList <ClassProDetailsEntity> GetListByPropertyId(int propertyid, int parentid, bool cache = false)
        {
            IList <ClassProDetailsEntity> list = null;

            if (cache)
            {
                string _cachekey = "ClassProDetailsList_" + propertyid + parentid;
                object obj       = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    list = ClassProDetailsDA.Instance.GetListByPropertyId(propertyid, parentid);
                    MemCache.AddCache(_cachekey, list);
                }
                else
                {
                    list = (IList <ClassProDetailsEntity>)obj;
                }
            }
            else
            {
                list = ClassProDetailsDA.Instance.GetListByPropertyId(propertyid, parentid);
            }

            return(list);
        }
Exemplo n.º 31
0
        /// <summary>
        /// 根据主键获取一个ClassProDetails实体记录。
        /// 该方法提供给其他实体的业务逻辑层(Logic)方法调用
        /// </summary>
        /// <returns>ClassProDetails实体</returns>
        /// <param name="columns">要返回的列</param>
        public ClassProDetailsEntity GetClassProDetails(int id, bool cache = false)
        {
            ClassProDetailsEntity list = null;

            if (cache)
            {
                string _cachekey = "GetClassProDetails_" + id;

                object obj = MemCache.GetCache(_cachekey);
                if (obj == null)
                {
                    list = ClassProDetailsDA.Instance.GetClassProDetails(id);
                    MemCache.AddCache(_cachekey, list);
                }
                else
                {
                    list = (ClassProDetailsEntity)obj;
                }
            }
            else
            {
                list = ClassProDetailsDA.Instance.GetClassProDetails(id);
            }
            return(list);
        }
Exemplo n.º 32
0
        /// <summary>
        /// 根据分类id 获取对应的分类产品属性
        /// </summary>
        /// <param name="classid"></param>
        /// <param name="pid"></param>
        /// <returns></returns>
        public IList <VWProductStyleSpecEntity> GetListByStyle(int styleid, int specid)
        {
            string _cachekey = "VWProductStyleSpecEntity" + "_" + styleid + "_" + specid;// SysCacheKey.VWProductStyleSpecKey;
            object _objcache = MemCache.GetCache(_cachekey);
            IList <VWProductStyleSpecEntity> _objlistall = new List <VWProductStyleSpecEntity>();

            if (_objcache == null)
            {
                _objlistall = ProductStyleSpecDA.Instance.GetListByStyle(styleid, specid);
                MemCache.AddCache(_cachekey, _objlistall);
            }
            else
            {
                _objlistall = (List <VWProductStyleSpecEntity>)_objcache;
            }
            var templist = from c in _objlistall
                           orderby c.Sort descending, c.SpecDetailName
            select c;

            if (templist == null)
            {
                return(null);
            }
            else
            {
                return(templist.ToList <VWProductStyleSpecEntity>());
            }
        }
Exemplo n.º 33
0
 public async Task Should_renew_age_when_returned__when_configured(bool renewAge) {
     _cache = new MemCache<int, string>(3, TimeSpan.FromMilliseconds(49));
     _cache.AutoRenew = renewAge;
     _cache.Add(1, "a");
     await Task.Delay(25);
     _cache.Get(1);
     await Task.Delay(25);
     Assert.AreEqual(renewAge ? "a" : null, _cache.Get(1));
 }
Exemplo n.º 34
0
 public void If_I_Try_To_Add_A_KeyValuePair_Structure()
 {
     string itemInCache = "The quick brown fox jumps over the lazy dog";
     string key = "MS'_favorite_pangram";
     //
     ICache cache = new MemCache();
     bool result = cache.Add<string>(new KeyValuePair<string, string>(key, itemInCache));
     //
     Assert.IsTrue(result);
 }
Exemplo n.º 35
0
 public void If_I_Try_To_Add_An_Item_To_Cache_It_Must_Returns_True()
 {
     string itemInCache = "The quick brown fox jumps over the lazy dog";
     string key = "MS'_favorite_pangram";
     //
     ICache cache = new MemCache();
     bool result = cache.Add<string>(itemInCache, key);
     //
     Assert.IsTrue(result);
 }
Exemplo n.º 36
0
 public void If_I_Try_To_Add_An_Existent_Item_It_Must_Returns_False()
 {
     string itemInCache = "The quick brown fox jumps over the lazy dog";
     string anotherItem = "justanotheritem";
     string key = "MS'_favorite_pangram";
     ICache cache = new MemCache();
     //
     bool firstAddition = cache.Add<string>(itemInCache, key);
     bool secondAddition = cache.Add<string>(anotherItem, key);
     //
     Assert.IsFalse(secondAddition);
 }
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            RouteConfig.RegisterRoutes(RouteTable.Routes);

            /*
             Google Maps Clustering
            */
            var filepath = string.Concat(HttpContext.Current.Server.MapPath("~"), @"App_Data\Points.csv");
            var memcache = new MemCache();
            var pointsDatabase = new PointsDatabase(memcache, filepath);
            var mapService = new MapService(pointsDatabase, memcache);
            Map.MapService = mapService; // Simulate putting data in session, probably dont do this in production where you put data in static class

            RegisterRoutes();

            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); // use JSON
        }
Exemplo n.º 38
0
        public void BuildUnityContainer()
        {
            /*
             *
             * Unity默认情况下会自动帮我们维护好这些对象的生命周
             *
             * TransientLifetimeManager,瞬态生命周期,默认情况下,在使用RegisterType进行对象关系注册时如果没有指定生命周期管理器则默认使用这个生命周期管理器,这个生命周期管理器就如同其名字一样,当使用这种管理器的时候,每次通过Resolve或ResolveAll调用对象的时候都会重新创建一个新的对象。
             *
             * ContainerControlledLifetimeManager,容器控制生命周期管理,这个生命周期管理器是RegisterInstance默认使用的生命周期管理器,也就是单件实例,UnityContainer会维护一个对象实例的强引用,每次调用的时候都会返回同一对象
             *
            */

            container = new UnityContainer();

            NameValueCollection nvc = ConfigurationManager.AppSettings;
            string serverList = nvc["ServerList"];
            string cachedArea = nvc["CachedArea"];
            string[] serverIp = serverList.Split(',');
            ISession mySession = new MemSession(serverIp, int.Parse(nvc["SessionExpireHours"]), nvc["SessionCookieDomain"], nvc["SessionArea"]);
            container.RegisterInstance(typeof(ISession), mySession);
            ICache myCache = new MemCache(serverIp, cachedArea);
            //ICache myCache = new OCSCache();
            container.RegisterInstance(typeof(ICache), myCache);
            container.RegisterType(typeof(ICache), typeof(AppCache), "AppCache");

            #region 新的数据访问方式
            string readConn = ConfigurationManager.ConnectionStrings["MvcSeedRead"].ConnectionString;
            string writeConn = ConfigurationManager.ConnectionStrings["MvcSeedWrite"].ConnectionString;
            container.RegisterType(typeof(IUnitOfWork), typeof(DefaultUnitOfWork), "ReadUnitOfWork", new InjectionConstructor(readConn));
            container.RegisterType(typeof(IUnitOfWork), typeof(DefaultUnitOfWork), "WriteUnitOfWork", new InjectionConstructor(writeConn));

            #endregion

            #region 接口映射

            #endregion
        }
Exemplo n.º 39
0
 public void If_I_Try_To_Add_Null_Key_Value_Pair_It_Must_Throws_Exception()
 {
     ICache cache = new MemCache();
     cache.Add<string>(null, null);
 }
Exemplo n.º 40
0
 public async Task Should_not_return_expired() {
     _cache = new MemCache<int, string>(3, TimeSpan.FromMilliseconds(49));
     _cache.Add(1, "a");
     await Task.Delay(50);
     Assert.AreEqual(null, _cache.Get(1));
 }
Exemplo n.º 41
0
 public void SetUp() {
     _cache = new MemCache<int, string>(3, TimeSpan.FromMilliseconds(1000));
 }
Exemplo n.º 42
0
 public MemoryCacheIntegrationTests()
 {
     _key = Guid.NewGuid().ToString();
     _cacheImplementation = new MemCache(TimeSpan.FromMinutes(1));
 }