コード例 #1
0
        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.Name, instance), GetCacheItemPolicy(removedCallback, cacheDependency));
            }
        }
コード例 #2
0
ファイル: TenantEngine.cs プロジェクト: vin-e/Vindation.CMS
        private TenantInstance StartInstance(Tenant tenant)
        {
            var instance = new TenantInstance(tenant);
            runningInstances.Add(instance, ShutdownInstance);

            Log("Started instance '{0}'", instance.Id);
            return instance;
        }
コード例 #3
0
ファイル: TenantEngine.cs プロジェクト: vin-e/Vindation.CMS
        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();
            }
        }