Exemplo n.º 1
0
        public IList <ResourceRequiredContext> CombineStylesheets(
            IList <ResourceRequiredContext> resources,
            ICombinatorSettings settings)
        {
            var hashCode = resources.GetResourceListHashCode();
            var lockName = MakeLockName(hashCode);

            return(_lockingCacheManager.Get(lockName, ctx =>
            {
                if (!_cacheFileService.Exists(hashCode))
                {
                    Combine(resources, hashCode, ResourceType.Style, settings);
                }

                _combinatorEventMonitor.MonitorCacheEmptied(ctx);

                return ProcessCombinedResources(_cacheFileService.GetCombinedResources(hashCode));
            }, () => resources));
        }
Exemplo n.º 2
0
 /// <summary>
 /// Tries to get the cache entry, if none is present, tries to acquire a lock on the entry so any other process simultaneously requesting the entry
 /// has to wait.
 /// </summary>
 /// <typeparam name="TResult">Type of the computation's result</typeparam>
 /// <param name="key">Key for the cache entry</param>
 /// <param name="acquire">Delegate for acquiring the cache entry</param>
 /// <param name="fallback">If the lock couldn't be acquired and the process timed out, this delegate will be run</param>
 /// <returns>Result of either the acquire or the fallback delegate</returns>
 public static TResult Get <TResult>(this ILockingCacheManager lockingCacheManager, string key, Func <AcquireContext <string>, TResult> acquire, Func <TResult> fallback)
 {
     return(lockingCacheManager.Get(key, acquire, fallback, new TimeSpan(0, 0, 4)));
 }