Exemplo n.º 1
0
        public void Add(string nodeId, TCacheItem item, int expirationSecond, bool absExpire)
        {
            CacheManager man = _cacheMans.GetCacheManager(nodeId);

            //serialize data
            byte[]        data;
            CacheDataType dataType;

            DataSerialize.Serialize(item.Value, out data, out dataType);

            CacheItem ci = new CacheItem(item.Key, data, item.ItemTime, (int)dataType);

            man.Set(ci, expirationSecond, absExpire);
        }
Exemplo n.º 2
0
        public void ProcessRequest(HandlerContext context)
        {
            _responseHeader               = context.ResponseHeader;
            _responseHeader.Server       += ";\x20" + ThumbCachedHttpHandler.HANDLER_NAME;
            _responseHeader.ContentLength = 0;

            TcdUrlParser urlParser = null;

            try
            {
                urlParser = new TcdUrlParser(context.RequestHeader.Url);
            }
            catch
            {
                _responseHeader.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            try
            {
                _cacheManager = _cacheManCollection.GetCacheManager(context.BindEndPointName);
            }
            catch
            {
                _responseHeader.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            if (string.IsNullOrEmpty(urlParser.ItemKey))
            {
                _responseHeader.Status = System.Net.HttpStatusCode.BadRequest;
                return;
            }

            if (urlParser.Action == ActionType.Update)
            {
                _canAcceptRequestContent = true;

                _requestStream = new MemoryStream();

                //get item info
                _itemKey = urlParser.ItemKey;
                _itemExpirationSecond = urlParser.ExpirationSecond;
                _itemAbsExpire        = urlParser.AbsoluteExpire;

                string lastModified = context.RequestHeader.Headers.Get("Last-Modified");
                if (lastModified != null)
                {
                    _itemTime = DateTime.Parse(lastModified).ToLocalTime(); //conver to local time
                }

                string contentType = context.RequestHeader.ContentType;
                if (contentType != null)
                {
                    int pos = contentType.IndexOf('/');
                    if (pos > 0)
                    {
                        _itemProperties = int.Parse(contentType.Substring(pos + 1));
                    }
                }
            }
            else
            {
                _responseHeader.Status = System.Net.HttpStatusCode.BadRequest;
            }
        }