Esempio n. 1
0
        public static List <PetLink> GetPetLinkList(Guid providerGroupId)
        {
            // Step 1. Get List
            List <PetLink> petLinkList = new GetPetLinkList()
            {
                ProviderGroupId = providerGroupId
            }.ExecuteList();

            HttpContext httpContext = HttpContext.Current;

            if (httpContext != null)
            {
                // Active Dependency
                CacheDependency cacheDependency = new CacheDependency(null, new string[] { GetActiveProviderGroupCacheKey(providerGroupId) });

                httpContext.Cache.Insert(GetPetLinkListCacheKey(providerGroupId), petLinkList, null, DateTime.Now.AddSeconds(GetPetLinkListExpirationInSeconds()), Cache.NoSlidingExpiration, PetLinkListCacheItemUpdateCallbackMethod);
            }

            return(petLinkList);
        }
Esempio n. 2
0
        public static void PetLinkListCacheItemUpdateCallbackMethod(string key, CacheItemUpdateReason reason, out object expensiveObject, out CacheDependency dependency, out DateTime absoluteExpiration, out TimeSpan slidingExpiration)
        {
            // Step 0.
            expensiveObject    = null;
            dependency         = null;
            absoluteExpiration = DateTime.Now.AddSeconds(GetPetLinkListExpirationInSeconds());
            slidingExpiration  = Cache.NoSlidingExpiration;

            if (DateTime.Now.Minute % 10 == 0)
            {
                return; // do nothing
            }

            // Step 1. Parse Key
            Guid?providerGroupId = GetPetLinkListCacheKeyProviderGroupId(key);

            if (providerGroupId != null)
            {
                expensiveObject = new GetPetLinkList()
                {
                    ProviderGroupId = providerGroupId.Value
                }.ExecuteList();
            }
        }