Exemplo n.º 1
0
        private void CacheCustomer(ICustomerBase customer)
        {
            // set/reset the cookie
            // TODO decide how we want to deal with cookie persistence options
            var cookie = new HttpCookie(ConsumerCookieKey)
            {
                Value = EncryptionHelper.Encrypt(customer.EntityKey.ToString())
            };

            _umbracoContext.HttpContext.Response.Cookies.Add(cookie);

            _cache.RequestCache.GetCacheItem(ConsumerCookieKey, () => customer.EntityKey);
            _cache.RuntimeCache.GetCacheItem(CacheKeys.CostumerCacheKey(customer.EntityKey), () => customer, TimeSpan.FromMinutes(5), true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to either retrieve an anonymous customer or an existing customer
        /// </summary>
        /// <param name="key">The key of the customer to retrieve</param>
        private void TryGetCustomer(Guid key)
        {
            var customer = (ICustomerBase)_cache.RuntimeCache.GetCacheItem(CacheKeys.CostumerCacheKey(key));

            // check the cache for a previously retrieved customer
            if (customer != null)
            {
                CurrentCustomer = customer;
                return;
            }

            // If the member has been authenticated there is no need to create an anonymous record.
            // Either return an existing customer or create a new one for the member.
            //if (_umbracoContext.Security.IsMemberAuthorized())
            //{
            //    var member = Member.GetCurrentMember();

            //    customer = _customerService.GetByMemberId(member.Id) ??
            //                   _customerService.CreateCustomerWithId(member.Id);

            //    CacheCustomer(customer);
            //    CurrentCustomer = customer;

            //    return;
            //}

            // try to get the customer
            customer = _customerService.GetAnyByKey(key);

            if (customer != null)
            {
                CurrentCustomer = customer;
                CacheCustomer(customer);
            }
            else // create a new anonymous customer
            {
                CreateAnonymousCustomer();
            }
        }