/// <summary> /// Clears the internal Engine caches. /// </summary> public static void ClearCache() { CacheInvalidator.InvalidateCaches(ClrProvider); UserTypeMetadataCaches.InvalidateCache(); GlobalCache.Processes.Clear(); GlobalCache.Caches.InvalidateCache(); }
public void Test_OnRelationshipChange() { CacheInvalidator <int, string> cacheInvalidator; ICache <int, string> cache; EntityRef[] testRelationshipTypes; const int numRelationshipTypes = 10; Func <long, bool> relationshipTypesToRemove; cache = new DictionaryCache <int, string>(); for (int i = 0; i < numRelationshipTypes; i++) { cache.Add(i, i.ToString()); } relationshipTypesToRemove = e => e % 2 == 0; // All even numbered relationship types. testRelationshipTypes = Enumerable.Range(0, numRelationshipTypes) .Where(i => relationshipTypesToRemove(i)) .Select(i => new EntityRef(i)).ToArray(); cacheInvalidator = new CacheInvalidator <int, string>(cache, "a"); for (int i = 0; i < numRelationshipTypes; i++) { using (CacheContext cacheContext = new CacheContext()) { cacheContext.RelationshipTypes.Add(i); cacheInvalidator.AddInvalidations(cacheContext, i); } } cacheInvalidator.OnRelationshipChange(testRelationshipTypes); Assert.That(cache.Where(ce => relationshipTypesToRemove(ce.Key)), Is.Empty); }
public void Test_ItemsRemoved() { CacheInvalidator <int, string> cacheInvalidator; ICache <int, string> cache; const int testKey1 = 42; const int testKey2 = 54; const string testValue1 = "foo"; const string testValue2 = "bar"; cache = new DictionaryCache <int, string>(); cache.Add(testKey1, testValue1); cache.Add(testKey2, testValue2); cacheInvalidator = new CacheInvalidator <int, string>(cache, "foo"); using (CacheContext cacheContext = new CacheContext()) { cacheContext.Entities.Add(testKey1); cacheInvalidator.AddInvalidations(cacheContext, testKey1); } using (CacheContext cacheContext = new CacheContext()) { cacheContext.Entities.Add(testKey2); cacheInvalidator.AddInvalidations(cacheContext, testKey2); } cache.Remove(testKey1); Assert.That(cacheInvalidator.EntityToCacheKey.Keys, Has.None.EqualTo(testKey1)); Assert.That(cacheInvalidator.EntityToCacheKey.Keys, Has.Exactly(1).EqualTo(testKey2)); }
/// <summary> /// Initializes the <see cref="VSContext"/> class. /// </summary> static VSContext() { InitializeDTE(); DesignModeCacheInvalidator = new CacheInvalidator(); InteractiveExecutionInitialization = new InteractiveExecutionInitialization(new VSInteractiveExecutionBehavior(), DesignModeCacheInvalidator); DebuggerEnteredDesignMode += () => DesignModeCacheInvalidator.InvalidateCache(); }
public void Test_OnFieldChange_NullFieldTypes() { CacheInvalidator <int, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <int, string>(new DictionaryCache <int, string>(), "a"); Assert.That(() => cacheInvalidator.OnFieldChange(null), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("fieldTypes")); }
public void Test_OnEntityChange_NullEntities() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(null, InvalidationCause.Save, null), Throws.TypeOf <ArgumentNullException>().And.Property("ParamName").EqualTo("entities")); }
/// <summary> /// Clears the internal Engine caches. /// </summary> public static void ClearCache() { CacheInvalidator.InvalidateCaches(ClrProvider); GlobalCache.Processes.Clear(); GlobalCache.UserTypeCastedVariableCollections.Clear(); GlobalCache.UserTypeCastedVariables.Clear(); GlobalCache.VariablesUserTypeCastedFields.Clear(); GlobalCache.VariablesUserTypeCastedFieldsByName.Clear(); }
public void Test_OnEntityChange_InvalidCause() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(new IEntity[0], (InvalidationCause)42, null), Throws.ArgumentException.And.Property("ParamName").EqualTo("cause")); }
public void Test_OnEntityChange_EntitiesContainsNull() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnEntityChange(new IEntity[] { null }, InvalidationCause.Save, null), Throws.ArgumentException.And.Property("ParamName").EqualTo("entities")); }
public void Test_OnRelationshipChange_RelationshipTypesContainsNull() { CacheInvalidator <string, string> cacheInvalidator; cacheInvalidator = new CacheInvalidator <string, string>(new DictionaryCache <string, string>(), "a"); Assert.That(() => cacheInvalidator.OnRelationshipChange(new EntityRef[] { null }), Throws.ArgumentException.And.Property("ParamName").EqualTo("relationshipTypes")); }
/// <summary> /// Create a new <see cref="CachingBulkRequestRunner" />. /// </summary> public CachingBulkRequestRunner( ) { var cacheFactory = new CacheFactory { BlockIfPending = true }; Cache = cacheFactory.Create <CachingBulkRequestRunnerKey, CachingBulkRequestRunnerValue>("Bulk Request Runner"); _cacheInvalidator = new CacheInvalidator <CachingBulkRequestRunnerKey, CachingBulkRequestRunnerValue>(Cache, "Bulk Request Runner"); }
public ActionResult Flush(string organisationId, string applicationId) { var cacheInvalidator = new CacheInvalidator(_cacheConfiguration); cacheInvalidator.SetCacheEngine(_cacheEngine); cacheInvalidator.Invalidate(new CacheInvalidationItem( CacheProfiles.Applications, CacheKeys.Applications.Key(organisationId, applicationId))); return(Content("Cache Flushed")); }
/// <summary> /// Construct a new <see cref="CachingEntityMemberRequestFactory"/>. /// </summary> /// <param name="factory"> /// The inner <see cref="IEntityMemberRequestFactory"/> whose results are cached. /// This cannot be null. /// </param> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> public CachingEntityMemberRequestFactory(IEntityMemberRequestFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } Factory = factory; Cache = CacheFactory.CreateSimpleCache <long, EntityMemberRequest>("Entity Member Request"); _cacheInvalidator = new EntityMemberRequestCacheInvalidator(Cache); CacheInvalidator = _cacheInvalidator; }
public async Task Refresh(string key, Func <Task <IDocument> > doc, Func <Task <Stream> > stream) { if (!AllocatedFiles.Contains(key)) { AllocatedFiles.Add(key); await CacheInvalidator.Allocated(key, doc, stream); } else { await CacheInvalidator.Refresh(key, doc, stream); } }
public void Enumerate() { DictionaryCache <int, string> dictionaryCache; SimpleCache <int> simpleCache; using (CacheInvalidator cacheInvalidator = new CacheInvalidator()) { dictionaryCache = cacheInvalidator.CreateDictionaryCache <int, string>(key => key.ToString()); simpleCache = cacheInvalidator.CreateSimpleCache(() => 42); dictionaryCache.TryGetValue(simpleCache.Value, out string testValue); Assert.NotEmpty(cacheInvalidator); } }
public void InvalidateStruct() { DifferentCachesStruct differentCaches = new DifferentCachesStruct(false); Assert.False(differentCaches.simpleCache.Cached); Assert.False(differentCaches.simpleCacheStruct.Cached); Assert.Equal(42, differentCaches.SimpleCacheValue); Assert.Equal(42, differentCaches.SimpleCacheStructValue); Assert.True(differentCaches.simpleCache.Cached); Assert.True(differentCaches.simpleCacheStruct.Cached); CacheInvalidator.InvalidateCaches(ref differentCaches); Assert.False(differentCaches.simpleCache.Cached); Assert.False(differentCaches.simpleCacheStruct.Cached); }
public void ComplexTest() { DictionaryCache <int, string> dictionaryCache; SimpleCache <int> simpleCache; using (CacheInvalidator cacheInvalidator = new CacheInvalidator()) { dictionaryCache = cacheInvalidator.CreateDictionaryCache <int, string>(key => key.ToString()); simpleCache = cacheInvalidator.CreateSimpleCache(() => 42); dictionaryCache.TryGetValue(simpleCache.Value, out string testValue); } Assert.Equal(0, dictionaryCache.Count); Assert.False(simpleCache.Cached); }
public HttpResponseMessage Delete(string orgId, string applicationId) { var cacheInvalidator = new CacheInvalidator(_cacheConfiguration) { Auditor = Auditor }; cacheInvalidator.SetCacheEngine(_cacheEngine); cacheInvalidator.Invalidate(new CacheInvalidationItem( CacheProfiles.Applications, CacheKeys.Applications.Key(orgId, applicationId))); return(Request.CreateResponse(HttpStatusCode.OK)); }
public void Test_OnEntityChange_EntityTypes() { MockRepository mockRepository; CacheInvalidator <long, string> cacheInvalidator; ICache <long, string> cache; IEntity[] testEntities; Mock <IEntity> mockEntity; const int numEntities = 10; const long typeIdOffset = 100; mockRepository = new MockRepository(MockBehavior.Loose); testEntities = new IEntity[numEntities]; for (int i = 0; i < testEntities.Length; i++) { mockEntity = mockRepository.Create <IEntity>(); mockEntity.SetupGet(e => e.Id).Returns(i); mockEntity.SetupGet(e => e.TypeIds).Returns(new [] { typeIdOffset + 100 }); testEntities[i] = mockEntity.Object; } cache = new DictionaryCache <long, string>(); for (int i = 0; i < numEntities; i++) { cache.Add(i, i.ToString()); } cacheInvalidator = new CacheInvalidator <long, string>(cache, "a"); // Make the second and third entities depend on the type of the first. using (CacheContext cacheContext = new CacheContext()) { cacheContext.EntityTypes.Add(testEntities[0].TypeIds.First()); // Will convert to EntityRef using this ID cacheInvalidator.AddInvalidations(cacheContext, testEntities[1].Id); cacheInvalidator.AddInvalidations(cacheContext, testEntities[2].Id); } // Save the first entity (only) cacheInvalidator.OnEntityChange(new [] { testEntities[0] }, InvalidationCause.Save, null); Assert.That( cache.Select(ce => ce.Key), Is.EquivalentTo( testEntities.Select(er => er.Id) .Where(id => id != testEntities[1].Id && id != testEntities[2].Id)), "Second and third entities (only) have not been removed"); }
public void InvalidateCaches() { DictionaryCache <int, string> dictionaryCache; SimpleCache <int> simpleCache; CacheTestClass test = new CacheTestClass(); test.CacheInvalidator = new CacheInvalidator(); dictionaryCache = test.CacheInvalidator.CreateDictionaryCache <int, string>(key => key.ToString()); simpleCache = test.CacheInvalidator.CreateSimpleCache(() => 42); dictionaryCache.TryGetValue(simpleCache.Value, out string testValue); CacheInvalidator.InvalidateCaches(test); CacheInvalidator.InvalidateCaches <CacheTestClass>(null); CacheInvalidator.InvalidateCaches(new CacheTestClass()); Assert.Equal(0, dictionaryCache.Count); Assert.False(simpleCache.Cached); }
/// <summary> /// Constructor /// </summary> /// <param name="cacheName">Name of the cache service.</param> /// <param name="cacheFactory">Cache factory to use.</param> protected GenericCacheService(string cacheName, CacheFactory cacheFactory) { if (string.IsNullOrEmpty(cacheName)) { throw new ArgumentNullException("cacheName"); } if (cacheFactory == null) { throw new ArgumentNullException("cacheFactory"); } CacheName = cacheName; Cache = cacheFactory.Create <TKey, TValue>(cacheName); _cacheInvalidator = new CacheInvalidator <TKey, TValue>(Cache, CacheName); }
public void Test_AddInvalidations() { CacheInvalidator <string, string> cacheInvalidator; long testEntity; long testRelationshipType; long testFieldType; long testEntityInvalidatingRelationshipTypeRef; long testEntityTypeRef; cacheInvalidator = new CacheInvalidator <string, string>( new DictionaryCache <string, string>(), "foo"); testEntity = 1; testRelationshipType = 2; testFieldType = 3; testEntityInvalidatingRelationshipTypeRef = 4; testEntityTypeRef = 5; using (CacheContext cacheContext = new CacheContext()) { cacheContext.Entities.Add(testEntity); cacheContext.RelationshipTypes.Add(testRelationshipType); cacheContext.FieldTypes.Add(testFieldType); cacheContext.EntityInvalidatingRelationshipTypes.Add(testEntityInvalidatingRelationshipTypeRef); cacheContext.EntityTypes.Add(testEntityTypeRef); // Sanity check Assert.That(cacheInvalidator.EntityToCacheKey, Has.Property("Keys").Empty); Assert.That(cacheInvalidator.RelationshipTypeToCacheKey, Has.Property("Keys").Empty); Assert.That(cacheInvalidator.FieldTypeToCacheKey, Has.Property("Keys").Empty); Assert.That(cacheInvalidator.EntityInvalidatingRelationshipTypesToCacheKey, Has.Property("Keys").Empty); Assert.That(cacheInvalidator.EntityTypeToCacheKey, Has.Property("Keys").Empty); cacheInvalidator.AddInvalidations(cacheContext, "foo"); Assert.That(cacheInvalidator.EntityToCacheKey, Has.Property("Keys").Exactly(1).EqualTo(testEntity)); Assert.That(cacheInvalidator.RelationshipTypeToCacheKey, Has.Property("Keys").Exactly(1).EqualTo(testRelationshipType)); Assert.That(cacheInvalidator.FieldTypeToCacheKey, Has.Property("Keys").Exactly(1).EqualTo(testFieldType)); Assert.That(cacheInvalidator.EntityInvalidatingRelationshipTypesToCacheKey, Has.Property("Keys").Exactly(1).EqualTo(testEntityInvalidatingRelationshipTypeRef)); Assert.That(cacheInvalidator.EntityTypeToCacheKey, Has.Property("Keys").Exactly(1).EqualTo(testEntityTypeRef)); } }
public void InvalidateObject() { DifferentCaches differentCaches = new DifferentCaches(); Assert.False(differentCaches.simpleCache.Cached); Assert.False(differentCaches.simpleCacheStruct.Cached); Assert.False(differentCaches.simpleCacheWithContext.Cached); Assert.Equal(42, differentCaches.SimpleCacheValue); Assert.Equal(42, differentCaches.SimpleCacheStructValue); Assert.Equal(42, differentCaches.SimpleCacheWithContextValue); Assert.True(differentCaches.simpleCache.Cached); Assert.True(differentCaches.simpleCacheStruct.Cached); Assert.True(differentCaches.simpleCacheWithContext.Cached); CacheInvalidator.InvalidateCaches(differentCaches); Assert.False(differentCaches.simpleCache.Cached); Assert.False(differentCaches.simpleCacheStruct.Cached); Assert.False(differentCaches.simpleCacheWithContext.Cached); }
public void Test_Ctor() { CacheInvalidator <string, int> cacheInvalidator; ICache <string, int> cache; const string testName = "name"; cache = new DictionaryCache <string, int>(); cacheInvalidator = new CacheInvalidator <string, int>(cache, testName); Assert.That(cacheInvalidator, Has.Property("Name").EqualTo(testName)); Assert.That(cacheInvalidator, Has.Property("Cache").EqualTo(cache)); Assert.That(cacheInvalidator, Has.Property("EntityToCacheKey").Property("Keys").Empty); Assert.That(cacheInvalidator, Has.Property("FieldTypeToCacheKey").Property("Keys").Empty); Assert.That(cacheInvalidator, Has.Property("RelationshipTypeToCacheKey").Property("Keys").Empty); Assert.That(cacheInvalidator, Has.Property("EntityInvalidatingRelationshipTypesToCacheKey").Property("Keys").Empty); Assert.That(cacheInvalidator, Has.Property("EntityTypeToCacheKey").Property("Keys").Empty); Assert.That(cacheInvalidator, Has.Property("TraceCacheInvalidationFactory").Not.Null); }
public void Test_GetTraceCacheInvalidationSetting() { bool oldSetting; bool newSetting; CacheInvalidator <int, int> cacheInvalidator; oldSetting = ConfigurationSettings.GetServerConfigurationSection().Security.CacheTracing; try { newSetting = !oldSetting; ConfigurationSettings.GetServerConfigurationSection().Security.CacheTracing = newSetting; cacheInvalidator = new CacheInvalidator <int, int>(new DictionaryCache <int, int>(), "Test"); Assert.That(cacheInvalidator.TraceCacheInvalidations, Is.EqualTo(newSetting)); } finally { ConfigurationSettings.GetServerConfigurationSection().Security.CacheTracing = oldSetting; } }
public async Task <bool> TryAllocate(string key, Func <Task <IDocument> > doc, Func <Task <Stream> > stream) { if (AllocatedFiles.Count >= MaxAllocatedFiles && CacheInvalidator != null) { int filesToDeallocate = 1 + (AllocatedFiles.Count - MaxAllocatedFiles); IEnumerable <Task> deallocateAwait = CacheInvalidator.DeallocatePriorityFiles.Result .Take(filesToDeallocate) .SelectMany(x => OnDeallocate.Select(y => y(x))); await Task.WhenAll(deallocateAwait); } if (!AllocatedFiles.Contains(key)) { AllocatedFiles.Add(key); await CacheInvalidator.Allocated(key, doc, stream); return(true); } else { return(false); } }
public async Task Copied(string from, string to) { await CacheInvalidator.Copied(from, to); }
/// <summary> /// Initializes a new instance of the <see cref="InteractiveExecutionInitialization" /> class. /// </summary> /// <param name="interactiveExecutionBehavior">Customization of interactive execution.</param> /// <param name="cacheInvalidator">Cache invalidator that will be used to create simple cache for creating interactive execution.</param> public InteractiveExecutionInitialization(InteractiveExecutionBehavior interactiveExecutionBehavior, CacheInvalidator cacheInvalidator = null) { InteractiveExecutionBehavior = interactiveExecutionBehavior; if (cacheInvalidator != null) { InteractiveExecutionCache = cacheInvalidator.CreateSimpleCache(CreateInteractiveExecution); } else { InteractiveExecutionCache = SimpleCache.Create(CreateInteractiveExecution); } }
/// <summary> /// Initializes a new instance of the <see cref="InteractiveExecutionInitialization" /> class. /// </summary> /// <param name="cacheInvalidator">Cache invalidator that will be used to create simple cache for creating interactive execution.</param> public InteractiveExecutionInitialization(CacheInvalidator cacheInvalidator = null) : this(new InteractiveExecutionBehavior(), cacheInvalidator) { }
/// <summary> /// Invalidates cache structures. /// Use when memory state changes (e.g. during live debugging). /// </summary> public void InvalidateProcessCache() { CacheInvalidator.InvalidateCaches(this); }