public void Resolve_twice_with_no_CompressionType_does_not_cache_compressed_result()
        {
            var xmlResult = ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                null,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.EqualTo(xmlModel));

            xmlResult = ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                null,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.EqualTo(xmlModel));

            var cachedResult = cacheClient.Get <ModelWithIdAndName>(CacheKey);

            ModelWithIdAndName.AssertIsEqual(model, cachedResult);

            var serializedCacheKey     = ContentCacheManager.GetSerializedCacheKey(CacheKey, MimeTypes.Xml);
            var serializedCachedResult = cacheClient.Get <string>(serializedCacheKey);

            Assert.That(serializedCachedResult, Is.EqualTo(xmlModel));

            AssertNoCompressedResults(cacheClient, serializedCacheKey);
        }
 /// <summary>
 /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
 /// optimized result based on the MimeType and CompressionType from the IRequestContext.
 /// </summary>
 public static object ToOptimizedResultUsingCache <T>(
     this IRequestContext requestContext, ICacheClient cacheClient, string cacheKey,
     Func <T> factoryFn)
     where T : class
 {
     return(ContentCacheManager.Resolve(
                factoryFn, requestContext, cacheClient, cacheKey, null));
 }
 /// <summary>
 /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
 /// optimized result based on the MimeType and CompressionType from the IRequestContext.
 /// <param name="expireCacheIn">How long to cache for, null is no expiration</param>
 /// </summary>
 public static object ToOptimizedResultUsingCache <T>(
     this IRequestContext requestContext, ICacheClient cacheClient, string cacheKey,
     TimeSpan?expireCacheIn, Func <T> factoryFn)
     where T : class
 {
     return(ContentCacheManager.Resolve(
                factoryFn, requestContext.MimeType, requestContext.CompressionType,
                cacheClient, cacheKey, expireCacheIn));
 }
        /// <summary>
        /// Overload for the <see cref="ContentCacheManager.Resolve"/> method returning the most
        /// optimized result based on the MimeType and CompressionType from the IRequestContext.
        /// The default ICacheClient registered in the AppHost will be used.
        /// </summary>
        public static object ToOptimizedResultUsingCache <T>(this IRequestContext requestContext,
                                                             string cacheKey, Func <T> factoryFn)
            where T : class
        {
            var cacheClient = GetDefaultCacheClient();

            return(ContentCacheManager.Resolve(
                       factoryFn, requestContext.MimeType, requestContext.CompressionType,
                       cacheClient, cacheKey, null));
        }
        public void Clear_after_Resolve_with_MimeType_clears_all_cached_results()
        {
            ContentCacheManager.Resolve(
                () => model,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
        public void Clear_after_Resolve_with_MimeType_and_CompressionType_clears_all_cached_results()
        {
            ContentCacheManager.Resolve(
                () => model,
                MimeTypes.Xml,
                CompressionTypes.Deflate,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
        public void Clear_after_Resolve_with_MimeType_and_CompressionType_clears_all_cached_results()
        {
            var serializationContext = new SerializationContext(MimeTypes.Xml)
            {
                CompressionType = CompressionTypes.Deflate
            };

            ContentCacheManager.Resolve(
                () => model,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            ContentCacheManager.Clear(cacheClient, CacheKey);

            AssertEmptyCache(cacheClient, CacheKey);
        }
        public void Can_cache_null_result()
        {
            var xmlResult = ContentCacheManager.Resolve <ModelWithIdAndName>(
                () => null,
                serializationContext,
                cacheClient,
                CacheKey,
                null);

            Assert.That(xmlResult, Is.Null);

            var cachedResult = cacheClient.Get <ModelWithIdAndName>(CacheKey);

            Assert.That(cachedResult, Is.Null);

            var serializedCacheKey     = ContentCacheManager.GetSerializedCacheKey(CacheKey, MimeTypes.Xml);
            var serializedCachedResult = cacheClient.Get <string>(serializedCacheKey);

            Assert.That(serializedCachedResult, Is.Null);

            AssertNoCompressedResults(cacheClient, serializedCacheKey);
        }