Example #1
0
        /// <summary>
        /// Indicates whether the current results can be cached based on the current invocation provided (should only be used by <see cref="CacheInterceptor"/> in the <see cref="CacheInterceptor.AfterExecution"/> method.
        /// </summary>
        public bool IsResultCacheable(IInvocation currentInvocation, LazyCacheAttributes cacheAttributes)
        {
            // If the current result may have been modified from its original state, and the current (AfterExecution) invocation resulted in subsequent service calls...
            if (CurrentResultProcessedForModification && OtherServiceCallsMadeFrom(currentInvocation))
            {
                // If method being invoked is NOT marked as always safe to cache (developer has asserted that no sensitive information is being used in a model derived from contained service calls)
                // then we cannot cache the current results
                if (!cacheAttributes.IsAlwaysSafeToCache)
                {
                    string message = string.Format(
@"Result not cached: {0}.{1}
    NOTE: Use the 'AlwaysSafeToCache' attribute on the service method to assert that this derived model is safe to cache from a security perspective.",
                        currentInvocation.InvocationTarget.GetType().FullName,
                        currentInvocation.Method.Name);

                    errorLog.Warn(message);

                    // Result cannot be cached
                    return false;
                }
            }

            // Result is cacheable
            return true;
        }
Example #2
0
        private object GetValueToCache(IInvocation invocation, LazyCacheAttributes cacheAttributes)
        {
            object cacheValue;

            if (cacheAttributes.CopyOnSet || cacheAttributes.CopyOnGet)
            {
                cacheValue = serializer.Serialize(invocation.ReturnValue);
            }
            else
            {
                cacheValue = invocation.ReturnValue;
            }

            return cacheValue;
        }
Example #3
0
        private LazyCacheAttributes GetCacheAttributes(MethodInfo invocationTarget)
        {
            LazyCacheAttributes result;

            if (!cacheAttributesByMethodInfo.TryGetValue(invocationTarget, out result))
            {
                result = new LazyCacheAttributes(invocationTarget.GetCustomAttributes(true));
                cacheAttributesByMethodInfo[invocationTarget] = result;
            }

            return result;
        }