/// <summary> /// Obtain an <see cref="INamedCache"/> interface that provides a view /// of resources shared among members of a cluster. /// </summary> /// <remarks> /// The view is identified by name within this ICacheService. /// Typically, repeated calls to this method with the same view name /// will result in the same view reference being returned. /// </remarks> /// <param name="name"> /// The name, within this ICacheService, that uniquely identifies a /// view; <c>null</c> is legal, and may imply a default name. /// </param> /// <returns> /// An <b>INamedCache</b> interface which can be used to access the /// resources of the specified view. /// </returns> /// <exception cref="InvalidOperationException"> /// If the service is not running. /// </exception> public virtual INamedCache EnsureCache(string name) { if (StringUtils.IsNullOrEmpty(name)) { name = "Default"; } ScopedReferenceStore storeCache = StoreRemoteNamedCache; RemoteNamedCache cache = storeCache.GetCache(name) as RemoteNamedCache; if (cache == null || !cache.IsActive) { lock (storeCache) { cache = storeCache.GetCache(name) as RemoteNamedCache; if (cache == null || !cache.IsActive) { cache = CreateRemoteNamedCache(name); storeCache.PutCache(cache); } } } return(cache); }
/// <summary> /// Obtain an <see cref="INamedCache"/> interface that provides a view /// of resources shared among members of a cluster. /// </summary> /// <remarks> /// The view is identified by name within this ICacheService. /// Typically, repeated calls to this method with the same view name /// will result in the same view reference being returned. /// </remarks> /// <param name="name"> /// The name, within this ICacheService, that uniquely identifies a /// view; <c>null</c> is legal, and may imply a default name. /// </param> /// <returns> /// An <b>INamedCache</b> interface which can be used to access the /// resources of the specified view. /// </returns> /// <exception cref="InvalidOperationException"> /// If the service is not running. /// </exception> public INamedCache EnsureCache(string name) { if (string.IsNullOrEmpty(name)) { name = "Default"; } ScopedReferenceStore storeCache = StoreSafeNamedCache; SafeNamedCache cacheSafe = (SafeNamedCache)storeCache.GetCache(name); if (cacheSafe == null) { lock (storeCache) { INamedCache cache = RunningCacheService.EnsureCache(name); cacheSafe = new SafeNamedCache { SafeCacheService = this, CacheName = name, NamedCache = cache, Principal = Thread.CurrentPrincipal }; storeCache.PutCache(cacheSafe); } } return(cacheSafe); }