public void Add(TenantInstance instance, Action<string, TenantInstance> removedCallback) { if (instance == null) { throw new ArgumentNullException("instance"); } if (removedCallback == null) { removedCallback = delegate { }; } // Add a cache entry for the instance id that will be used as a cache dependency // for the running instances var cacheDependencyPolicy = new CacheItemPolicy { // Make the "MaxAge" configurable - when the dependency is removed so are the instances AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(12) }; var cacheDependency = new CacheItem(instance.Id.ToString(), instance.Id); // We need to add the dependency before we set up the instance change monitors, // otherwise they'll be removed from the cache immediately! cache.Set(instance.Id.ToString(), instance.Id, cacheDependencyPolicy); // Now cache the running instance for each identifier // The policies must be unique since the RemovedCallback can only be called once-per-policy foreach (var id in instance.Tenant.RequestIdentifiers) { cache.Set(new CacheItem(id, instance), GetCacheItemPolicy(removedCallback, cacheDependency)); } }
public void Add(TenantInstance instance, Action <string, TenantInstance> removedCallback) { if (instance == null) { throw new ArgumentNullException("instance"); } if (removedCallback == null) { removedCallback = delegate { }; } // Add a cache entry for the instance id that will be used as a cache dependency // for the running instances var cacheDependencyPolicy = new CacheItemPolicy { // Make the "MaxAge" configurable - when the dependency is removed so are the instances AbsoluteExpiration = DateTimeOffset.UtcNow.AddHours(12) }; var cacheDependency = new CacheItem(instance.Id.ToString(), instance.Id); // We need to add the dependency before we set up the instance change monitors, // otherwise they'll be removed from the cache immediately! cache.Set(instance.Id.ToString(), instance.Id, cacheDependencyPolicy); // Now cache the running instance for each identifier // The policies must be unique since the RemovedCallback can only be called once-per-policy foreach (var id in instance.Tenant.RequestIdentifiers) { cache.Set(new CacheItem(id, instance), GetCacheItemPolicy(removedCallback, cacheDependency)); } }
private TenantInstance StartInstance(ITenant tenant) { var instance = new TenantInstance(tenant); runningInstances.Add(instance, ShutdownInstance); Log("Started instance '{0}'", instance.Id); return(instance); }
private void ShutdownInstance(string identifier, TenantInstance instance) { if (instance == null) { return; } // Make sure all cache entries for this instance are removed (they are all dependent on tenant instance id) Log("Removing instance '{0}' identifier '{1}'", instance.Id, identifier); runningInstances.Remove(instance.Id.ToString()); lock (instance) { instance.Dispose(); } }
private TenantInstance StartInstance(ITenant tenant) { var instance = new TenantInstance(tenant); runningInstances.Add(instance, ShutdownInstance); Log("Started instance '{0}'", instance.Id); return instance; }