コード例 #1
0
        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);
        }
コード例 #2
0
 /// <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));
 }
コード例 #3
0
 /// <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));
 }
コード例 #4
0
        /// <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));
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }