public void SetSlice(DatastoreEntities context, SummarySlice slice, int repositoryId, SummarySliceValue results) { if (!ConfigHelper.AllowCaching) { return; } int changeStamp = 0; int queryHash = 0; CacheResultsSlice item; using (var q = new AcquireReaderLock(QueryCacheID, "QueryCache")) { //Do not cache big items if (results.RecordList.Count > 500) { return; } if (slice.Query != null && !string.IsNullOrEmpty(slice.Query.Keyword) && !ConfigHelper.AllowCacheWithKeyword) { return; } queryHash = slice.GetHashCode(); changeStamp = RepositoryManager.GetRepositoryChangeStamp(context, repositoryId); item = _cacheSlice.FirstOrDefault(x => x.QueryHash == queryHash && x.RepositoryId == repositoryId && x.ChangeStamp == changeStamp); //If data has not changed and results are in cache then do nothing except mark as accessed if (item != null) { item.Results = results; item.Timestamp = DateTime.Now; return; } } using (var q = new AcquireWriterLock(QueryCacheID, "QueryCache")) { //Remove previous cache _cacheSlice.RemoveAll(x => x.QueryHash == queryHash && x.RepositoryId == repositoryId); //Create a new cache item item = new CacheResultsSlice() { QueryHash = queryHash, RepositoryId = repositoryId, ChangeStamp = changeStamp, Results = results, QueryString = slice.ToString(), ParentId = RepositoryManager.GetSchemaParentId(repositoryId), }; _cacheSlice.Add(item); } }
private static SummarySlice BuildDataSliceQueryFromParser(DatastoreExpressionParser parser) { var dataQuery = new SummarySlice(); if (parser.Query.FieldFilters != null) { dataQuery.Query.FieldFilters = parser.Query.FieldFilters; } if (parser.Query.FieldSorts != null) { dataQuery.Query.FieldSorts = parser.Query.FieldSorts; } dataQuery.Query.PageOffset = parser.Query.PageOffset; dataQuery.Query.RecordsPerPage = parser.Query.RecordsPerPage; if (parser.Query.Keyword != null) { dataQuery.Query.Keyword = parser.Query.Keyword; } if (parser.Users != null) { dataQuery.Query.UserList = parser.Users; } if (parser.Query.DimensionValueList != null) { dataQuery.Query.DimensionValueList = parser.Query.DimensionValueList; } if (parser.Query.SkipDimensions != null) { dataQuery.Query.SkipDimensions = parser.Query.SkipDimensions; } dataQuery.GroupFields = parser.SliceQuery.GroupFields; dataQuery.SpliceDName = parser.SliceQuery.SpliceDName; return(dataQuery); }
public SummarySliceValue GetSlice(DatastoreEntities context, SummarySlice slice, int repositoryId) { if (!ConfigHelper.AllowCaching) { return(null); } using (var q = new AcquireReaderLock(QueryCacheID, "QueryCache")) { var queryHash = slice.GetHashCode(); var changeStamp = RepositoryManager.GetRepositoryChangeStamp(context, repositoryId); var item = _cacheSlice.FirstOrDefault(x => x.QueryHash == queryHash && x.RepositoryId == repositoryId && x.ChangeStamp == changeStamp); if (item == null) { return(null); } item.Timestamp = DateTime.Now; item.HitCount++; return(item.Results); } }
/// <summary /> public virtual SummarySliceValue CalculateSlice(SummarySlice query) { ValidateService(); return(DataModelService.CalculateSlice(this.RepositoryId, query)); }