public IList <CombinatorResource> GetCombinedResources(int hashCode) { return(_cacheManager.Get(MakeCacheKey("GetCombinedResources." + hashCode.ToString()), ctx => { _combinatorEventMonitor.MonitorCacheEmptied(ctx); var files = GetRecords(hashCode); var fileCount = files.Count; var resources = new List <CombinatorResource>(fileCount); foreach (var file in files) { var resource = _combinatorResourceManager.ResourceFactory(file.Type); resource.FillRequiredContext( "CombinedResource" + file.Id.ToString(), _storageProvider.GetPublicUrl(MakePath(file))); _combinatorResourceManager.DeserializeSettings(file.Settings, resource); resource.LastUpdatedUtc = file.LastUpdatedUtc ?? _clock.UtcNow; resources.Add(resource); } return resources; })); }
public IList <CombinatorResource> GetCombinedResources(string fingerprint, ICombinatorSettings settings) { IList <CombinatorResource> sharedResources = new List <CombinatorResource>(); if (settings.EnableResourceSharing) { CallOnDefaultShell(cacheFileService => sharedResources = cacheFileService.GetCombinedResources(fingerprint, new CombinatorSettings(settings) { EnableResourceSharing = false })); } var cacheKey = MakeCacheKey("GetCombinedResources." + fingerprint); return(_cacheService.Get(cacheKey, () => { _combinatorEventMonitor.MonitorCacheEmptied(cacheKey); _combinatorEventMonitor.MonitorBundleChanged(cacheKey, fingerprint); var files = _fileRepository.Fetch(file => file.Fingerprint == ConvertFingerprintToStorageFormat(fingerprint)).ToList(); var fileCount = files.Count; var resources = new List <CombinatorResource>(fileCount); foreach (var file in files) { var resource = _combinatorResourceManager.ResourceFactory(file.Type); resource.FillRequiredContext("CombinedResource" + file.Id.ToString(), string.Empty); _combinatorResourceManager.DeserializeSettings(file.Settings, resource); if (!resource.IsOriginal) // If the resource is original its url was filled from the settings { resource.RequiredContext.Resource.SetUrl(_storageProvider.GetPublicUrl(MakePath(file))); } resource.LastUpdatedUtc = file.LastUpdatedUtc.HasValue ? file.LastUpdatedUtc.Value : _clock.UtcNow; resources.Add(resource); } // This way if a set of resources contains shared and local resources in two resource sets then both will be returned. // Issue: the order is not necessarily correctly kept... But this should be a rare case. Should be solved eventually. return sharedResources.Union(resources).ToList(); })); }
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)); }