Exemple #1
0
        /// <summary>
        /// Writes the cache directive to the operation context.
        /// </summary>
        /// <param name="directive"></param>
        /// <param name="operationContext"></param>
        protected internal static void WriteCachingDirectiveHeaders(ResponseCachingDirective directive, OperationContext operationContext)
        {
            // add caching directive to WCF message headers so that we send it to the client
            var header = MessageHeader.CreateHeader(HeaderName, HeaderNamespace, directive);

            operationContext.OutgoingMessageHeaders.Add(header);
        }
Exemple #2
0
 /// <summary>
 /// Implemented by the subclass to cache the response, based on the specified caching directive.
 /// </summary>
 /// <param name="invocation"></param>
 /// <param name="cacheClient"></param>
 /// <param name="cacheKey"></param>
 /// <param name="region"></param>
 /// <param name="directive"></param>
 protected abstract void CacheResponse(IInvocation invocation, ICacheClient cacheClient, string cacheKey, string region, ResponseCachingDirective directive);
Exemple #3
0
        /// <summary>
        /// Puts the invocation response in the specified cache.
        /// </summary>
        /// <param name="invocation"></param>
        /// <param name="cacheClient"></param>
        /// <param name="cacheKey"></param>
        /// <param name="region"></param>
        /// <param name="directive"></param>
        protected static void PutResponseInCache(IInvocation invocation, ICacheClient cacheClient, string cacheKey, string region, ResponseCachingDirective directive)
        {
            // bail if the directive does not tell us to cache anything
            if (directive == null || !directive.EnableCaching || directive.TimeToLive == TimeSpan.Zero)
            {
                return;
            }

            // if we don't have a cache key, this is an error
            if (cacheKey == null)
            {
                throw new InvalidOperationException(
                          string.Format("{0} is cacheable but the request class does not implement IDefinesCacheKey.", invocation.GetType().FullName));
            }

            // put response in cache
            cacheClient.Put(cacheKey, invocation.ReturnValue, new CachePutOptions(region, directive.TimeToLive, false));
        }
Exemple #4
0
 /// <summary>
 /// Implemented by the subclass to cache the response, based on the specified caching directive.
 /// </summary>
 protected override void CacheResponse(IInvocation invocation, ICacheClient cacheClient, string cacheKey, string region, ResponseCachingDirective directive)
 {
     // put the response in the local cache
     PutResponseInCache(invocation, cacheClient, cacheKey, region, directive);
 }