示例#1
0
        public DependencyState GetState(DependencyStateContext context)
        {
            if (!(context is CacheEntryDependencyStateContext))
            {
                return(null);
            }

            // Attempt to get the requested entry from the cache
            var cacheContext = (CacheEntryDependencyStateContext)context;
            var entry        = CacheProvider.Check(cacheContext.Key);

            // If the entry doesn't exist, return a "null" state.
            if (entry == null)
            {
                return(new DependencyState(
                           context: context,
                           state: 0));
            }

            // Create a state that is the hash of the matching keys' states.
            var hash = entry
                       .DependencyStates
                       .Where(state => !(state.Context is CacheEntryDependencyStateContext))
                       .Aggregate(0L, (agg, state) => agg ^ state.State);

            return(new DependencyState(
                       context: context,
                       state: hash));
        }