protected virtual async Task <ClaimsIdentity> GetIdentityByUserId(string userId) { var cacheKey = CacheKey.Create(CacheGroup, "GetIdentityByUserId", userId); var result = await Options.CacheManager.Get(cacheKey, () => CreateIdentityByUserId(userId)); return(result); }
private Category GetCategoryById(string categoryId) { var cacheKey = CacheKey.Create("CatalogOutlineBuilder.GetCategoryById", categoryId); var retVal = _cacheManager.Get(cacheKey, () => _categoryService.GetById(categoryId)); return(retVal); }
public T ExecuteScalar <T>(QueryDescription query, ObjectBinder objectBinder) { var key = CacheKey.Create(new HiveQueryCacheKey(query)); Func <T> execution = () => PerformExecuteScalar <T>(query, objectBinder); var cacheCheck = ContextCacheAvailable() ? HiveContext.GenerationScopedCache.GetOrCreate(key, execution) : null; //var performExecute = PerformExecuteScalar<T>(query, objectBinder); var performExecute = cacheCheck != null ? cacheCheck.Value.Item : execution.Invoke(); if ((!typeof(T).IsValueType && performExecute == null) || performExecute.Equals(default(T))) { return(default(T)); } if (typeof(IReferenceByHiveId).IsAssignableFrom(typeof(T))) { ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, (IReferenceByHiveId)performExecute); } if (typeof(IRelatableEntity).IsAssignableFrom(typeof(T))) { this.SetRelationProxyLazyLoadDelegate((IRelatableEntity)performExecute); } return(performExecute); }
public IEnumerable <T> ExecuteMany <T>(QueryDescription query, ObjectBinder objectBinder) { var key = CacheKey.Create(new HiveQueryCacheKey(query)); Func <List <T> > execution = () => { var executeItems = PerformExecuteMany <T>(query, objectBinder) ?? Enumerable.Empty <T>(); return(executeItems.ToList()); // Ensure the executed sequence is cached }; var cacheCheck = ContextCacheAvailable() ? HiveContext.GenerationScopedCache.GetOrCreate(key, execution) : null; var performExecute = cacheCheck != null ? cacheCheck.Value.Item : execution.Invoke(); //var performExecute = PerformExecuteMany<T>(query, objectBinder) ?? Enumerable.Empty<T>(); var items = performExecute .ForAllThatAre <T, IReferenceByHiveId>(entity => ProviderRepositoryHelper.SetProviderAliasOnId(ProviderMetadata, entity)) .ForAllThatAre <T, IRelatableEntity>(entity => this.SetRelationProxyLazyLoadDelegate(entity)); if (query.From.RequiredEntityIds.Any() && !query.SortClauses.Any()) { // Return in same order as supplied ids return(query.From.RequiredEntityIds.Select(x => items.OfType <IReferenceByHiveId>().FirstOrDefault(y => y.Id.Value == x.Value)).WhereNotNull().OfType <T>()); } return(items); }
private bool CanGenerateAFAMultiEventListPipe() { var typeOfTKey = typeof(TKey); var typeOfTPayload = typeof(TPayload); var typeOfTRegister = typeof(TRegister); if (!typeOfTPayload.CanRepresentAsColumnar()) { return(false); } if (!typeOfTRegister.CanRepresentAsColumnar()) { return(false); } if (typeOfTKey.GetPartitionType() != null) { return(false); } var lookupKey = CacheKey.Create((object)this.afa); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => AfaMultiEventListTemplate.GenerateAFA(this)); this.errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
public TagIndex(CacheStream cache, IReadOnlyList <string> paths) : base(cache) { var binaryReader = new BinaryReader(cache); _classes = new List <TagClassHeirarchy>(new TagClassHeirarchy[classArrayCount]); for (var i = 0; i < classArrayCount; i++) { _classes[i] = new TagClassHeirarchy(binaryReader.ReadTagClass(), binaryReader.ReadTagClass(), binaryReader.ReadTagClass()); } _data = new List <TagDatum>(new TagDatum[datumArrayCount]); var cacheKey = CacheKey.Create(cache); for (var i = 0; i < datumArrayCount && i < paths.Count; i++) { TagDatum data; do { data = new TagDatum { Class = binaryReader.ReadTagClass( ), Identifier = binaryReader.ReadTagIdent( ), VirtualAddress = binaryReader.ReadInt32( ), Length = binaryReader.ReadInt32( ), CacheKey = cacheKey }; } while (TagDatum.IsNull(data)); data.Path = paths[i]; _data[i] = data; } }
public coreModel.Store GetById(string id) { var cacheKey = CacheKey.Create("StoreModule", "GetById", id); return(_cacheManager.Get(cacheKey, () => { coreModel.Store retVal = null; using (var repository = _repositoryFactory()) { var entity = repository.GetStoreById(id); if (entity != null) { //Load original typed shipping method and populate it personalized information from db retVal = entity.ToCoreModel(_shippingService.GetAllShippingMethods(), _paymentService.GetAllPaymentMethods()); var fulfillmentCenters = _commerceService.GetAllFulfillmentCenters().ToList(); retVal.ReturnsFulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.ReturnsFulfillmentCenterId); retVal.FulfillmentCenter = fulfillmentCenters.FirstOrDefault(x => x.Id == entity.FulfillmentCenterId); retVal.SeoInfos = _commerceService.GetObjectsSeo(new[] { id }).ToList(); LoadObjectSettings(_settingManager, retVal); } } return retVal; })); }
public void CanRemoveItemFromCacheWithDelegate() { var myObject1 = new TestCacheObject("test-1"); var myObject2 = new TestCacheObject("bob"); var myObject3 = new TestCacheObject("frank"); CacheProvider.AddOrChangeValue(CacheKey.Create <string>("my-1"), myObject1); CacheProvider.AddOrChangeValue(CacheKey.Create <StrongClassKey>(x => x.MyName = "bob"), myObject2); CacheProvider.AddOrChangeValue(CacheKey.Create <StrongClassKey>(x => x.MyName = "frank"), myObject3); var resultFilterClause = new ResultFilterClause(typeof(string), ResultFilterType.Any, 0); var fromClause = new FromClause(HiveId.Empty.ToString(), HierarchyScope.AncestorsOrSelf, FixedStatusTypes.Published); var fieldPredicateExpression = new FieldPredicateExpression("title", ValuePredicateType.Equal, "blah"); //var key = new HiveQueryCacheKey(new QueryDescription(resultFilterClause, fromClause, fieldPredicateExpression, Enumerable.Empty<SortClause>())); var key = CacheKey.Create(new HiveQueryCacheKey(new QueryDescription(resultFilterClause, fromClause, fieldPredicateExpression, Enumerable.Empty <SortClause>()))); CacheProvider.AddOrChangeValue(key, myObject3); Assert.NotNull(CacheProvider.GetValue(CacheKey.Create <string>("my-1"))); Assert.NotNull(CacheProvider.GetValue(CacheKey.Create <StrongClassKey>(x => x.MyName = "bob"))); Assert.NotNull(CacheProvider.GetValue(CacheKey.Create <string>("my-1"))); Assert.NotNull(CacheProvider.GetValue(key)); CacheProvider.RemoveWhereKeyMatches <string>(x => x == "my-1"); CacheProvider.RemoveWhereKeyMatches <StrongClassKey>(x => x.MyName == "bob"); CacheProvider.RemoveWhereKeyMatches <HiveQueryCacheKey>(x => x.From.HierarchyScope == HierarchyScope.AncestorsOrSelf); Assert.Null(CacheProvider.Get(CacheKey.Create <string>("my-1"))); Assert.Null(CacheProvider.GetValue(CacheKey.Create <string>("my-1"))); Assert.Null(CacheProvider.Get(CacheKey.Create <StrongClassKey>(x => x.MyName = "bob"))); Assert.NotNull(CacheProvider.Get(CacheKey.Create <StrongClassKey>(x => x.MyName = "frank"))); }
private storeModel.Store GetStoreById(string storeId) { var cacheKey = CacheKey.Create("MP", "GetStoreById", storeId); var retVal = _cacheManager.Get(cacheKey, () => _storeService.GetById(storeId)); return(retVal); }
public IHttpActionResult GetStores() { var cacheKey = CacheKey.Create("MP", "GetStores"); var stores = _cacheManager.Get(cacheKey, this.GetFullLoadedStoreList); return(Ok(stores)); }
protected override bool CanGenerateColumnar() { var typeOfTKey = typeof(TKey); var typeOfTInput = typeof(TInput); var typeOfTOutput = typeof(TOutput); if (!typeOfTInput.CanRepresentAsColumnar()) { return(false); } if (typeOfTKey.GetPartitionType() != null) { return(false); } if (!typeOfTOutput.CanRepresentAsColumnar()) { return(false); } var lookupKey = CacheKey.Create(this.apt, GetAggregateFunctionsHashCode(this.Aggregate)); var tuple = cachedPipes.GetOrAdd(lookupKey, key => AggregateTemplate.Generate(this, this.apt)); var generatedPipeType = tuple.Item1; this.errorMessages = tuple.Item2; return(generatedPipeType != null); }
private bool CanGenerateColumnar() { var typeOfTOuterKey = typeof(TOuterKey); var typeOfTInnerKey = typeof(TInnerKey); var typeOfTResult = typeof(TResult); if (!typeOfTResult.CanRepresentAsColumnar()) { return(false); } if (typeOfTOuterKey.GetPartitionType() != null) { return(false); } if (typeOfTInnerKey.GetPartitionType() != null) { return(false); } // For now, restrict the inner key to be anything other than an anonymous type since those can't be ungrouped without using reflection. if (typeOfTInnerKey.IsAnonymousType()) { return(false); } var lookupKey = CacheKey.Create(ResultSelector.ExpressionToCSharp()); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => UngroupTemplate.Generate <TOuterKey, TInnerKey, TInnerResult, TResult>(ResultSelector)); errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
protected override bool CanGenerateColumnar() { var typeOfTKey = typeof(TKey); var typeOfTLeft = typeof(TLeft); var typeOfTRight = typeof(TRight); if (!typeOfTLeft.CanRepresentAsColumnar()) { return(false); } if (!typeOfTRight.CanRepresentAsColumnar()) { return(false); } if (typeOfTKey.GetPartitionType() != null) { return(false); } var lookupKey = CacheKey.Create(this.Properties.KeyEqualityComparer.GetEqualsExpr().ToString(), this.LeftComparer.GetEqualsExpr().ToString()); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => ClipJoinTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
public void SlidingExpiredItemIsRemoved() { var stringKey = CacheKey.Create <string>("hello"); var myObject1 = CacheProvider.GetOrCreate(stringKey, () => new CacheValueOf <TestCacheObject>(new TestCacheObject("hello-1"), new StaticCachePolicy(TimeSpan.FromSeconds(1)))); Assert.NotNull(myObject1); Assert.That(myObject1.AlreadyExisted, Is.False); Assert.That(myObject1.WasInserted, Is.True); Assert.NotNull(myObject1.Value); if (CacheIsAsync) { Thread.Sleep(500); } Assert.NotNull(CacheProvider.GetValue <TestCacheObject>(stringKey)); Assert.NotNull(CacheProvider.Get <TestCacheObject>(stringKey)); Thread.Sleep(TimeSpan.FromSeconds(1.2d)); Assert.Null(CacheProvider.Get <TestCacheObject>(stringKey)); }
private bool CanGenerateColumnar() { var typeOfTOuterKey = typeof(TOuterKey); var typeOfTSource = typeof(TSource); var typeOfTInnerKey = typeof(TInnerKey); if (!typeOfTSource.CanRepresentAsColumnar()) { return(false); } if (typeOfTOuterKey.GetPartitionType() != null) { return(false); } if (typeOfTInnerKey.GetPartitionType() != null) { return(false); } var lookupKey = CacheKey.Create(KeySelector.ToString()); var comparer = (Properties.KeyEqualityComparer as CompoundGroupKeyEqualityComparer <TOuterKey, TInnerKey>).innerComparer.GetGetHashCodeExpr(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate <TOuterKey, TSource, TInnerKey>(comparer, KeySelector, true)); errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
protected override bool CanGenerateColumnar() { var typeOfTKey = typeof(TKey); var typeOfTSource = typeof(TPayload); var typeOfTResult = typeof(TResult); if (!typeOfTSource.CanRepresentAsColumnar()) { return(false); } if (!typeOfTResult.CanRepresentAsColumnar()) { return(false); } if (typeOfTKey.GetPartitionType() != null) { return(false); } var lookupKey = CacheKey.Create(this.Selector.ExpressionToCSharp(), this.HasStartEdge, this.HasKey); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => SelectTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
private bool CanGenerateColumnar() { var typeOfTOuterKey = typeof(TOuterKey); var typeOfTSource = typeof(TSource); var typeOfTInnerKey = typeof(TInnerKey); if (!typeOfTSource.CanRepresentAsColumnar()) { return(false); } if (typeOfTOuterKey.GetPartitionType() != null) { return(false); } if (typeOfTInnerKey.GetPartitionType() != null) { return(false); } // For now, restrict the inner key to be anything other than an anonymous type since those can't be ungrouped without using reflection. if (typeOfTInnerKey.IsAnonymousType()) { return(false); } var lookupKey = CacheKey.Create(KeySelector.ToString()); var comparer = Properties.KeyEqualityComparer.GetGetHashCodeExpr(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => GroupTemplate.Generate <TOuterKey, TSource, TInnerKey>(comparer, KeySelector, false)); errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
public static MemoryPool <TKey, TPayload> GetMemoryPool <TKey, TPayload>(bool isColumnar = true) { if (Config.ForceRowBasedExecution) { isColumnar = false; } var typeOfTKey = typeof(TKey); var typeOfTPayload = typeof(TPayload); var cacheKey = CacheKey.Create(typeof(TKey), typeof(TPayload), isColumnar); if (!isColumnar || (!typeOfTKey.KeyTypeNeedsGeneratedMemoryPool() && typeOfTPayload.MemoryPoolHasGetMethodFor())) { return((MemoryPool <TKey, TPayload>)memoryPools.GetOrAdd(cacheKey, key => new MemoryPool <TKey, TPayload>(isColumnar))); } if (!typeOfTPayload.CanRepresentAsColumnar()) { return((MemoryPool <TKey, TPayload>)memoryPools.GetOrAdd(cacheKey, new MemoryPool <TKey, TPayload>(false))); } var lookupKey = CacheKey.Create(typeOfTKey, typeOfTPayload); Type generatedMemoryPool = cachedMemoryPools.GetOrAdd(lookupKey, key => Transformer.GenerateMemoryPoolClass <TKey, TPayload>()); return((MemoryPool <TKey, TPayload>)memoryPools.GetOrAdd(cacheKey, t => Activator.CreateInstance(generatedMemoryPool))); }
public coreModel.Store Create(coreModel.Store store) { var dbStore = store.ToDataModel(); using (var repository = _repositoryFactory()) { repository.Add(dbStore); CommitChanges(repository); } //Need add seo separately if (store.SeoInfos != null) { foreach (var seoInfo in store.SeoInfos) { seoInfo.ObjectId = dbStore.Id; seoInfo.ObjectType = typeof(coreModel.Store).Name; _commerceService.UpsertSeo(seoInfo); } } //Deep save settings SaveObjectSettings(_settingManager, store); //Reset cache var cacheKey = CacheKey.Create("StoreModule", "GetById", store.Id); _cacheManager.Remove(cacheKey); var retVal = GetById(store.Id); return(retVal); }
public void CanAddAtLeast300ItemsPerSecond() { var watch = new Stopwatch(); TypedEntity[] itemsToAdd = new TypedEntity[500]; for (int i = 0; i < 300; i++) { var item = HiveModelCreationHelper.MockTypedEntity(true); itemsToAdd[i] = item; } watch.Start(); for (int i = 0; i < 300; i++) { CacheProvider.AddOrChangeValue(CacheKey.Create("Item " + i), itemsToAdd[i]); } watch.Stop(); var writeElapsed = watch.Elapsed; watch.Reset(); watch.Start(); for (int i = 0; i < 300; i++) { var cacheKey = CacheKey.Create("Item " + i); var item = CacheProvider.Get <TypedEntity>(cacheKey); Assert.That(item, Is.Not.Null); } watch.Stop(); var readElapsed = watch.Elapsed; LogHelper.TraceIfEnabled <AbstractCacheProviderFixture>("Write Took (s): " + writeElapsed.TotalSeconds); LogHelper.TraceIfEnabled <AbstractCacheProviderFixture>("Read Took (s): " + readElapsed.TotalSeconds); Assert.That(writeElapsed, Is.LessThan(TimeSpan.FromSeconds(1))); Assert.That(readElapsed, Is.LessThan(TimeSpan.FromSeconds(1))); }
public void CacheKeySerializesToJson() { var key = CacheKey.Create <string>("my-1"); var keyString = key.ToString(); var keyJson = key.ToJson(); Assert.That(keyString, Is.EqualTo(keyJson)); }
private Tuple <Type, string> GetPipe() { var lookupKey = CacheKey.Create(this.apt, GetAggregateFunctionsHashCode(this.Aggregate)); var tuple = cachedPipes.GetOrAdd(lookupKey, key => AggregateTemplate.Generate(this, this.apt)); return(tuple); }
protected override bool CanGenerateColumnar() { var lookupKey = CacheKey.Create(); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => SessionWindowTemplate.Generate(this)); this.errorMessages = generatedPipeType.Item2; return(generatedPipeType.Item1 != null); }
public static ColumnPool <T> GetColumnPool <T>(int size = -1) { if (size == -1) { size = Config.DataBatchSize; } return((ColumnPool <T>)columnPools.GetOrAdd(CacheKey.Create(typeof(T), size), new ColumnPool <T>(size))); }
private UnaryPipe <TKey, TPayload, TRegister> GetAFAMultiEventListPipe(IStreamObserver <TKey, TRegister> observer) { var lookupKey = CacheKey.Create((object)this.afa); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => AfaMultiEventListTemplate.GenerateAFA(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, this.afa, this.MaxDuration); var returnValue = (UnaryPipe <TKey, TPayload, TRegister>)instance; return(returnValue); }
public void CacheKeyEquals() { var one = CacheKey.Create <string>("this"); var two = CacheKey.Create <string>("this"); var three = (CacheKey)(CacheKey <string>)two.ToJson(); Assert.That(one, Is.EqualTo(two)); Assert.That(two, Is.EqualTo(three)); Assert.That(two.GetHashCode(), Is.EqualTo(three.GetHashCode())); }
private EgressBoundary <PartitionKey <TKey>, TPayload, TResult> GetPipe(IObserver <TResult> observer) { var lookupKey = CacheKey.Create(this.constructor.Body.ExpressionToCSharp(), this.source.Properties.IsColumnar); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); var returnValue = (EgressBoundary <PartitionKey <TKey>, TPayload, TResult>)instance; return(returnValue); }
private UnaryPipe <Empty, TPayload, TRegister> GetUngroupedAFAPipe(IStreamObserver <Empty, TRegister> observer) { var lookupKey = CacheKey.Create((object)this.afa); var downcast = this as AfaStreamable <Empty, TPayload, TRegister, TAccumulator>; var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => UngroupedAfaTemplate.GenerateAFA(downcast)); var instance = Activator.CreateInstance(generatedPipeType.Item1, this, observer, this.afa, this.MaxDuration); var returnValue = (UnaryPipe <Empty, TPayload, TRegister>)instance; return(returnValue); }
public void HiveRelationCacheKeyToFromJson() { var guid = Guid.NewGuid(); var key = CacheKey.Create(new HiveRelationCacheKey(HiveRelationCacheKey.RepositoryTypes.Entity, new HiveId(guid), Direction.Siblings, FixedRelationTypes.ApplicationRelationType)); var keyJson = key.ToJson(); var keyBack = (CacheKey <HiveRelationCacheKey>)keyJson; var keyJsonTwice = keyBack.ToJson(); Assert.That(keyBack, Is.Not.Null); Assert.That(keyJson, Is.EqualTo(keyJsonTwice)); }
private EgressBoundary <Empty, TPayload, StreamEvent <TPayload> > GetPipe(IObserver <StreamEvent <TPayload> > observer) { var lookupKey = CacheKey.Create(this.source.Properties.IsColumnar); var generatedPipeType = cachedPipes.GetOrAdd(lookupKey, key => TemporalEgressTemplate.Generate(this)); var instance = Activator.CreateInstance(generatedPipeType.Item1, observer, this.container); var returnValue = (EgressBoundary <Empty, TPayload, StreamEvent <TPayload> >)instance; return(returnValue); }