ServiceStack.HttpResult.NotModified C# (CSharp) Method

NotModified() public static method

public static NotModified ( string description = null, CacheControl cacheControl = null, System.TimeSpan maxAge = null, string eTag = null, System.DateTime lastModified = null ) : HttpResult
description string
cacheControl CacheControl
maxAge System.TimeSpan
eTag string
lastModified System.DateTime
return HttpResult
        public static HttpResult NotModified(string description = null,
            CacheControl? cacheControl = null,
            TimeSpan? maxAge = null,
            string eTag = null,
            DateTime? lastModified = null)
        {
            return new HttpResult(HttpStatusCode.NotModified,
                description ?? HostContext.ResolveLocalizedString(LocalizedStrings.NotModified))
            {
                ETag = eTag,
                LastModified = lastModified,
                MaxAge = maxAge,
                CacheControl = cacheControl.GetValueOrDefault(CacheControl.None),
            };
        }

Usage Example

        public static object ResolveFromCache(this ICacheClient cacheClient,
                                              string cacheKey,
                                              IRequest request)
        {
            DateTime?lastModified;
            var      checkModifiedSince = CheckModifiedSince(request);

            string modifiers = null;

            if (!request.ResponseContentType.IsBinary())
            {
                if (request.ResponseContentType == MimeTypes.Json)
                {
                    string jsonp = request.GetJsonpCallback();
                    if (jsonp != null)
                    {
                        modifiers = ".jsonp," + jsonp.SafeVarName();
                    }
                }

                var cacheKeySerialized = GetCacheKeyForSerialized(cacheKey, request.ResponseContentType, modifiers);

                var  compressionType = request.GetCompressionType();
                bool doCompression   = compressionType != null;
                if (doCompression)
                {
                    var cacheKeySerializedZip = GetCacheKeyForCompressed(cacheKeySerialized, compressionType);

                    if (cacheClient.HasValidCache(request, cacheKeySerializedZip, checkModifiedSince, out lastModified))
                    {
                        return(HttpResult.NotModified());
                    }

                    if (request.Response.GetHeader(HttpHeaders.CacheControl) != null)
                    {
                        lastModified = null;
                    }

                    var compressedResult = cacheClient.Get <byte[]>(cacheKeySerializedZip);
                    if (compressedResult != null)
                    {
                        return(new CompressedResult(
                                   compressedResult,
                                   compressionType,
                                   request.ResponseContentType)
                        {
                            LastModified = lastModified,
                        });
                    }
                }
                else
                {
                    if (cacheClient.HasValidCache(request, cacheKeySerialized, checkModifiedSince, out lastModified))
                    {
                        return(HttpResult.NotModified());
                    }

                    var serializedResult = cacheClient.Get <string>(cacheKeySerialized);
                    if (serializedResult != null)
                    {
                        return(serializedResult);
                    }
                }
            }
            else
            {
                var cacheKeySerialized = GetCacheKeyForSerialized(cacheKey, request.ResponseContentType, modifiers);
                if (cacheClient.HasValidCache(request, cacheKeySerialized, checkModifiedSince, out lastModified))
                {
                    return(HttpResult.NotModified());
                }

                var serializedResult = cacheClient.Get <byte[]>(cacheKeySerialized);
                if (serializedResult != null)
                {
                    return(serializedResult);
                }
            }

            return(null);
        }
All Usage Examples Of ServiceStack.HttpResult::NotModified