/// <summary> /// Loads structured data for all entities of the specified type(s). /// The 'Entities' are interpreted as the types. /// </summary> /// <param name="request">The description of fields and related entities to load.</param> /// <returns>All instances of type 'entityType', and optionally all instances of types that derive from 'entityType'.</returns> public static IEnumerable <EntityData> GetEntities(EntityRequest request) { IEnumerable <EntityData> result; // Ensure cache is ready if (_securedResultCache == null) { _securedResultCache = Factory.Current.ResolveNamed <ICache <CachingBulkRequestRunnerKey, IEnumerable <EntityData> > >("BulkRequestRunner Secured Result"); } // Check request if (ShouldCacheAsMetadata(request)) { // Don't use the bulk request runner result cache when we're using the metadata cache. request.IgnoreResultCache = true; CachingBulkRequestRunnerKey key = CachingBulkRequestRunnerKey.Create(request); _securedResultCache.TryGetOrAdd(key, out result, key1 => { return(GetEntitiesRouteRequest(request)); }); } else { result = GetEntitiesRouteRequest(request); } return(result); }
/// <summary> /// Execute a request for bulk data from the SQL database. /// </summary> /// <param name="request">The requested data</param> /// <returns></returns> public BulkRequestResult GetBulkResult(EntityRequest request) { if (request == null) { throw new ArgumentNullException("request"); } // Bypass cache if (request.IgnoreResultCache) { return(CreateResult(request)); } BulkRequestResult result; CachingBulkRequestRunnerValue cacheValue; CachingBulkRequestRunnerKey key = CachingBulkRequestRunnerKey.Create(request); // Check cache bool inCache = Cache.TryGetValue(key, out cacheValue); // Should parent cache contexts be notified of invalidations // .. no for now, for compatibility with previous system. Consider changing bool notifyParentCacheContext = false; if (!inCache) { using (var cacheContext = new CacheContext(notifyParentCacheContext ? ContextType.New : ContextType.Detached)) // Detached for now.. { result = CreateResult(request); cacheValue = new CachingBulkRequestRunnerValue(result); Cache.Add(key, cacheValue); // Add the cache context entries to the appropriate CacheInvalidator cacheContext.Entities.Add(result.AllEntities.Keys); cacheContext.EntityInvalidatingRelationshipTypes.Add(GetRelationshipTypesUsed(result)); _cacheInvalidator.AddInvalidations(cacheContext, key); } } else { if (notifyParentCacheContext && CacheContext.IsSet( )) { using (CacheContext cacheContext = new CacheContext(ContextType.Attached)) { // Add the already stored changes that should invalidate this cache // entry to any outer or containing cache contexts. cacheContext.AddInvalidationsFor(_cacheInvalidator, key); } } } result = cacheValue.BulkRequestResult; request.ResultFromCache = inCache; // TODO: Find a better channel to return this info. (It can't be in the response, because that's cached) return(result); }