diff --git a/samples/TagHelperSample.Web/Components/FeaturedMoviesComponent.cs b/samples/TagHelperSample.Web/Components/FeaturedMoviesComponent.cs index f7a3156b93..cd24f107d5 100644 --- a/samples/TagHelperSample.Web/Components/FeaturedMoviesComponent.cs +++ b/samples/TagHelperSample.Web/Components/FeaturedMoviesComponent.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using Microsoft.AspNet.Mvc; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Primitives; using TagHelperSample.Web.Models; using TagHelperSample.Web.Services; @@ -25,15 +25,15 @@ namespace TagHelperSample.Web.Components public IViewComponentResult Invoke() { // Since this component is invoked from within a CacheTagHelper, - // cache the movie list and provide an expiration trigger, which when triggered causes the + // cache the movie list and provide an expiration token, which when notified causes the // CacheTagHelper's cached data to be invalidated. var cacheKey = "featured_movies"; IEnumerable movies; if (!_cache.TryGetValue(cacheKey, out movies)) { - IExpirationTrigger trigger; - movies = _moviesService.GetFeaturedMovies(out trigger); - _cache.Set(cacheKey, movies, new MemoryCacheEntryOptions().AddExpirationTrigger(trigger)); + IChangeToken expirationToken; + movies = _moviesService.GetFeaturedMovies(out expirationToken); + _cache.Set(cacheKey, movies, new MemoryCacheEntryOptions().AddExpirationToken(expirationToken)); } return View(movies); @@ -44,9 +44,9 @@ namespace TagHelperSample.Web.Components string quote; if (!_cache.TryGetValue(movieName, out quote)) { - IExpirationTrigger trigger; - quote = _moviesService.GetCriticsQuote(out trigger); - _cache.Set(movieName, quote, new MemoryCacheEntryOptions().AddExpirationTrigger(trigger)); + IChangeToken expirationToken; + quote = _moviesService.GetCriticsQuote(out expirationToken); + _cache.Set(movieName, quote, new MemoryCacheEntryOptions().AddExpirationToken(expirationToken)); } return Content(quote); diff --git a/samples/TagHelperSample.Web/Controllers/MoviesController.cs b/samples/TagHelperSample.Web/Controllers/MoviesController.cs index 736d9a35f3..c86cf9795e 100644 --- a/samples/TagHelperSample.Web/Controllers/MoviesController.cs +++ b/samples/TagHelperSample.Web/Controllers/MoviesController.cs @@ -15,9 +15,9 @@ namespace TagHelperSample.Web.Controllers _moviesService = moviesService; } - // Sample exhibiting the use of nested cache tag helpers with custom user expiration triggers. + // Sample exhibiting the use of nested cache tag helpers with custom user expiration tokens. // Trigger expirations cascade, expiration of the inner tag helper's content either due to absolute or sliding - // expiration or due to a user specified expiration trigger would cause the outer cache tag helper to also expire. + // expiration or due to a user specified expiration token would cause the outer cache tag helper to also expire. public IActionResult Index() { ViewData["Title"] = "Movies"; diff --git a/samples/TagHelperSample.Web/Services/MoviesService.cs b/samples/TagHelperSample.Web/Services/MoviesService.cs index e6c796e822..f16be1162d 100644 --- a/samples/TagHelperSample.Web/Services/MoviesService.cs +++ b/samples/TagHelperSample.Web/Services/MoviesService.cs @@ -5,8 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading; -using Microsoft.Framework.Caching; -using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Primitives; using TagHelperSample.Web.Models; namespace TagHelperSample.Web.Services @@ -18,11 +17,11 @@ namespace TagHelperSample.Web.Services private CancellationTokenSource _featuredMoviesTokenSource; private CancellationTokenSource _quotesTokenSource; - public IEnumerable GetFeaturedMovies(out IExpirationTrigger expirationTrigger) + public IEnumerable GetFeaturedMovies(out IChangeToken expirationToken) { _featuredMoviesTokenSource = new CancellationTokenSource(); - expirationTrigger = new CancellationTokenTrigger(_featuredMoviesTokenSource.Token); + expirationToken = new CancellationChangeToken(_featuredMoviesTokenSource.Token); return GetMovies().OrderBy(m => m.Rank).Take(2); } @@ -33,7 +32,7 @@ namespace TagHelperSample.Web.Services _featuredMoviesTokenSource = null; } - public string GetCriticsQuote(out IExpirationTrigger trigger) + public string GetCriticsQuote(out IChangeToken expirationToken) { _quotesTokenSource = new CancellationTokenSource(); @@ -45,7 +44,7 @@ namespace TagHelperSample.Web.Services "Bravo!" }; - trigger = new CancellationTokenTrigger(_quotesTokenSource.Token); + expirationToken = new CancellationChangeToken(_quotesTokenSource.Token); return quotes[_random.Next(0, quotes.Length)]; } diff --git a/src/Microsoft.AspNet.Mvc.Core/project.json b/src/Microsoft.AspNet.Mvc.Core/project.json index 05629aa374..cc7ac4a9c1 100644 --- a/src/Microsoft.AspNet.Mvc.Core/project.json +++ b/src/Microsoft.AspNet.Mvc.Core/project.json @@ -43,6 +43,10 @@ "System.Runtime": "" } }, - "dnxcore50": { } + "dnxcore50": { + "dependencies": { + "System.Text.Encoding": "4.0.11-*" + } + } } } diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs index 2f6cae5471..b7d32c1cc5 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/Directives/DefaultChunkTreeCache.cs @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Directives // negative results and adding a Watch for that file. var options = new MemoryCacheEntryOptions() - .AddExpirationTrigger(_fileProvider.Watch(pagePath)) + .AddExpirationToken(_fileProvider.Watch(pagePath)) .SetSlidingExpiration(SlidingExpirationDuration); var file = _fileProvider.GetFileInfo(pagePath); diff --git a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs index fc2c57bbc2..a39a61eb19 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Compilation/CompilerCache.cs @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation cacheResult = CompilerCacheResult.FileNotFound; cacheEntryOptions = new MemoryCacheEntryOptions(); - cacheEntryOptions.AddExpirationTrigger(_fileProvider.Watch(normalizedPath)); + cacheEntryOptions.AddExpirationToken(_fileProvider.Watch(normalizedPath)); } else { @@ -128,12 +128,12 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation private MemoryCacheEntryOptions GetMemoryCacheEntryOptions(string relativePath) { var options = new MemoryCacheEntryOptions(); - options.AddExpirationTrigger(_fileProvider.Watch(relativePath)); + options.AddExpirationToken(_fileProvider.Watch(relativePath)); var viewImportsPaths = ViewHierarchyUtility.GetViewImportsLocations(relativePath); foreach (var location in viewImportsPaths) { - options.AddExpirationTrigger(_fileProvider.Watch(location)); + options.AddExpirationToken(_fileProvider.Watch(location)); } return options; diff --git a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs index fa96f23e7b..e81f1ecca6 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/Precompilation/RazorPreCompiler.cs @@ -236,10 +236,10 @@ namespace Microsoft.AspNet.Mvc.Razor.Precompilation PrecompilationCacheEntry cacheEntry) { var options = new MemoryCacheEntryOptions(); - options.AddExpirationTrigger(FileProvider.Watch(fileInfo.RelativePath)); + options.AddExpirationToken(FileProvider.Watch(fileInfo.RelativePath)); foreach (var path in ViewHierarchyUtility.GetViewImportsLocations(fileInfo.RelativePath)) { - options.AddExpirationTrigger(FileProvider.Watch(path)); + options.AddExpirationToken(FileProvider.Watch(path)); } return options; } diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs index 606c99ff3c..279293aafb 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/CacheTagHelper.cs @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var key = GenerateKey(context); if (!MemoryCache.TryGetValue(key, out result)) { - // Create an entry link scope and flow it so that any triggers related to the cache entries + // Create an entry link scope and flow it so that any tokens related to the cache entries // created within this scope get copied to this scope. using (var link = MemoryCache.CreateLinkingScope()) { diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs index a9a116fb62..d1d36fb9fe 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs @@ -97,10 +97,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal if (!_cache.TryGetValue(path, out value)) { value = QueryHelpers.AddQueryString(path, VersionKey, GetHashForFile(fileInfo)); - _cache.Set( - path, - value, - new MemoryCacheEntryOptions().AddExpirationTrigger(_fileProvider.Watch(resolvedPath))); + var cacheEntryOptions = new MemoryCacheEntryOptions().AddExpirationToken(_fileProvider.Watch(resolvedPath)); + _cache.Set(path, value, cacheEntryOptions); } return value; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs index a62530f90d..7efe5a2f31 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/GlobbingUrlBuilder.cs @@ -115,8 +115,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal var options = new MemoryCacheEntryOptions(); foreach (var pattern in includePatterns) { - var trigger = FileProvider.Watch(pattern); - options.AddExpirationTrigger(trigger); + var changeToken = FileProvider.Watch(pattern); + options.AddExpirationToken(changeToken); } files = FindFiles(includePatterns, excludePatterns); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs index a6c7e8ebed..36b16eb9c9 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Host.Test/Directives/DefaultCodeTreeCacheTest.cs @@ -72,7 +72,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives Assert.Same(expected1, result1); // Act 2 - fileProvider.GetTrigger(path).IsExpired = true; + fileProvider.GetChangeToken(path).HasChanged = true; var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected2); // Assert 2 @@ -97,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives // Act 2 fileProvider.DeleteFile(path); - fileProvider.GetTrigger(path).IsExpired = true; + fileProvider.GetChangeToken(path).HasChanged = true; var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => { throw new Exception("Shouldn't be called."); }); // Assert 2 @@ -121,7 +121,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Host.Directives // Act 2 fileProvider.AddFile(path, "test content"); - fileProvider.GetTrigger(path).IsExpired = true; + fileProvider.GetChangeToken(path).HasChanged = true; var result2 = chunkTreeCache.GetOrAdd(path, fileInfo => expected); // Assert 2 diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs index 2950f337a3..9fe3259524 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/Compilation/CompilerCacheTest.cs @@ -111,9 +111,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation Assert.Same(expected, result1.CompilationResult); // Act 2 - // Delete the file from the file system and set it's expiration trigger. + // Delete the file from the file system and set it's expiration token. fileProvider.DeleteFile(ViewPath); - fileProvider.GetTrigger(ViewPath).IsExpired = true; + fileProvider.GetChangeToken(ViewPath).HasChanged = true; var result2 = cache.GetOrAdd(ViewPath, ThrowsIfCalled); // Assert 2 @@ -147,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation Assert.Same(expected1.CompiledType, result2.CompilationResult.CompiledType); // Act 3 - fileProvider.GetTrigger(ViewPath).IsExpired = true; + fileProvider.GetChangeToken(ViewPath).HasChanged = true; var result3 = cache.GetOrAdd(ViewPath, _ => expected2); // Assert 3 @@ -182,7 +182,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation Assert.Same(expected1.CompiledType, result2.CompilationResult.CompiledType); // Act 3 - fileProvider.GetTrigger(globalImportPath).IsExpired = true; + fileProvider.GetChangeToken(globalImportPath).HasChanged = true; var result3 = cache.GetOrAdd(ViewPath, _ => expected2); // Assert 2 @@ -242,7 +242,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation // Act fileProvider.Watch(PrecompiledViewsPath); - fileProvider.GetTrigger(PrecompiledViewsPath).IsExpired = true; + fileProvider.GetChangeToken(PrecompiledViewsPath).HasChanged = true; var result = cache.GetOrAdd(PrecompiledViewsPath, ThrowsIfCalled); // Assert @@ -260,7 +260,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Compilation // Act fileProvider.Watch(globalImportPath); - fileProvider.GetTrigger(globalImportPath).IsExpired = true; + fileProvider.GetChangeToken(globalImportPath).HasChanged = true; var result = cache.GetOrAdd(PrecompiledViewsPath, ThrowsIfCalled); // Assert diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/CacheTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/CacheTagHelperTest.cs index 2af71d44a6..e912eeeea4 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/CacheTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/CacheTagHelperTest.cs @@ -18,9 +18,9 @@ using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Internal; +using Microsoft.Framework.Primitives; using Moq; using Xunit; @@ -536,7 +536,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers { // Arrange var expiresSliding = TimeSpan.FromSeconds(30); - var expected = new[] { Mock.Of(), Mock.Of() }; + var expected = new[] { Mock.Of(), Mock.Of() }; var cache = new MemoryCache(new MemoryCacheOptions()); var cacheTagHelper = new CacheTagHelper(cache) { @@ -544,13 +544,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }; var entryLink = new EntryLink(); - entryLink.AddExpirationTriggers(expected); + entryLink.AddExpirationTokens(expected); // Act var cacheEntryOptions = cacheTagHelper.GetMemoryCacheEntryOptions(entryLink); // Assert - Assert.Equal(expected, cacheEntryOptions.Triggers.ToArray()); + Assert.Equal(expected, cacheEntryOptions.ExpirationTokens.ToArray()); } [Fact] @@ -722,7 +722,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var tokenSource = new CancellationTokenSource(); var cache = new MemoryCache(new MemoryCacheOptions()); var cacheEntryOptions = new MemoryCacheEntryOptions() - .AddExpirationTrigger(new CancellationTokenTrigger(tokenSource.Token)); + .AddExpirationToken(new CancellationChangeToken(tokenSource.Token)); var tagHelperContext = new TagHelperContext( allAttributes: new TagHelperAttributeList(), items: new Dictionary(), diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs index 802c91e6bc..43b0785bc3 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ImageTagHelperTest.cs @@ -17,8 +17,8 @@ using Microsoft.AspNet.Mvc.ViewEngines; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Routing; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders.Testing; using Moq; using Xunit; @@ -304,7 +304,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers mockFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny())) .Returns(mockFile.Object); mockFileProvider.Setup(fp => fp.Watch(It.IsAny())) - .Returns(new TestFileTrigger()); + .Returns(new TestFileChangeToken()); var hostingEnvironment = new Mock(); hostingEnvironment.Setup(h => h.WebRootFileProvider).Returns(mockFileProvider.Object); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs index b1d22494fe..5edea24555 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/FileVersionProviderTest.cs @@ -7,8 +7,8 @@ using System.Text; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Http; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Primitives; using Moq; using Xunit; @@ -54,7 +54,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal mockFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny())) .Returns(mockFile.Object); mockFileProvider.Setup(fp => fp.Watch(It.IsAny())) - .Returns(new TestFileTrigger()); + .Returns(new TestFileChangeToken()); var hostingEnvironment = new Mock(); hostingEnvironment.Setup(h => h.WebRootFileProvider).Returns(mockFileProvider.Object); @@ -137,10 +137,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal public void SetsValueInCache(string filePath, string watchPath, string requestPathBase) { // Arrange - var trigger = new Mock(); + var changeToken = new Mock(); var hostingEnvironment = GetMockHostingEnvironment(filePath, requestPathBase != null); Mock.Get(hostingEnvironment.WebRootFileProvider) - .Setup(f => f.Watch(watchPath)).Returns(trigger.Object); + .Setup(f => f.Watch(watchPath)).Returns(changeToken.Object); object cacheValue = null; var cache = new Mock(); @@ -197,7 +197,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal } mockFileProvider.Setup(fp => fp.Watch(It.IsAny())) - .Returns(new TestFileTrigger()); + .Returns(new TestFileChangeToken()); var hostingEnvironment = new Mock(); hostingEnvironment.Setup(h => h.WebRootFileProvider).Returns(mockFileProvider.Object); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs index ca24b76880..3d676d40e7 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/Internal/GlobbingUrlBuilderTest.cs @@ -6,10 +6,10 @@ using System.Collections.Generic; using System.Linq; using Microsoft.AspNet.FileProviders; using Microsoft.AspNet.Http; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.FileSystemGlobbing; using Microsoft.Framework.FileSystemGlobbing.Abstractions; +using Microsoft.Framework.Primitives; using Moq; using Xunit; @@ -272,9 +272,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal public void CachesMatchResults() { // Arrange - var trigger = new Mock(); + var changeToken = new Mock(); var fileProvider = MakeFileProvider(MakeDirectoryContents("site.css", "blank.css")); - Mock.Get(fileProvider).Setup(f => f.Watch(It.IsAny())).Returns(trigger.Object); + Mock.Get(fileProvider).Setup(f => f.Watch(It.IsAny())).Returns(changeToken.Object); var cache = MakeCache(); Mock.Get(cache).Setup(c => c.Set( /*key*/ It.IsAny(), diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LinkTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LinkTagHelperTest.cs index 23d5273c57..3cc2ce95b6 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LinkTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/LinkTagHelperTest.cs @@ -19,9 +19,9 @@ using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Routing; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Logging; +using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders.Testing; using Moq; using Xunit; @@ -871,7 +871,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers mockFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny())) .Returns(mockFile.Object); mockFileProvider.Setup(fp => fp.Watch(It.IsAny())) - .Returns(new TestFileTrigger()); + .Returns(new TestFileChangeToken()); var hostingEnvironment = new Mock(); hostingEnvironment.Setup(h => h.WebRootFileProvider).Returns(mockFileProvider.Object); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs index e8c4ad8e60..ddfab3fb8c 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs @@ -19,9 +19,9 @@ using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.AspNet.Routing; using Microsoft.Dnx.Runtime; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Logging; +using Microsoft.Framework.Primitives; using Microsoft.Framework.WebEncoders.Testing; using Moq; using Xunit; @@ -964,7 +964,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers mockFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny())) .Returns(mockFile.Object); mockFileProvider.Setup(fp => fp.Watch(It.IsAny())) - .Returns(new TestFileTrigger()); + .Returns(new TestFileChangeToken()); var hostingEnvironment = new Mock(); hostingEnvironment.Setup(h => h.WebRootFileProvider).Returns(mockFileProvider.Object); @@ -986,7 +986,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers .Returns(result != null); var cacheEntryOptions = new MemoryCacheEntryOptions(); - cacheEntryOptions.AddExpirationTrigger(new Mock().Object); + cacheEntryOptions.AddExpirationToken(Mock.Of()); cache .Setup( c => c.Set( diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestFileChangeToken.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestFileChangeToken.cs new file mode 100644 index 0000000000..b0d38f35b1 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.TestCommon/TestFileChangeToken.cs @@ -0,0 +1,19 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; + +namespace Microsoft.Framework.Primitives +{ + internal class TestFileChangeToken : IChangeToken + { + public bool ActiveChangeCallbacks => false; + + public bool HasChanged { get; set; } + + public IDisposable RegisterChangeCallback(Action callback, object state) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestFileProvider.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestFileProvider.cs index 2ec1396569..bc09ef6cbe 100644 --- a/test/Microsoft.AspNet.Mvc.TestCommon/TestFileProvider.cs +++ b/test/Microsoft.AspNet.Mvc.TestCommon/TestFileProvider.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.AspNet.FileProviders; -using Microsoft.Framework.Caching; +using Microsoft.Framework.Primitives; namespace Microsoft.AspNet.Mvc.Razor { @@ -13,8 +13,8 @@ namespace Microsoft.AspNet.Mvc.Razor { private readonly Dictionary _lookup = new Dictionary(StringComparer.Ordinal); - private readonly Dictionary _fileTriggers = - new Dictionary(StringComparer.Ordinal); + private readonly Dictionary _fileTriggers = + new Dictionary(StringComparer.Ordinal); public virtual IDirectoryContents GetDirectoryContents(string subpath) { @@ -58,19 +58,19 @@ namespace Microsoft.AspNet.Mvc.Razor } } - public virtual IExpirationTrigger Watch(string filter) + public virtual IChangeToken Watch(string filter) { - TestFileTrigger trigger; - if (!_fileTriggers.TryGetValue(filter, out trigger) || trigger.IsExpired) + TestFileChangeToken changeToken; + if (!_fileTriggers.TryGetValue(filter, out changeToken) || changeToken.HasChanged) { - trigger = new TestFileTrigger(); - _fileTriggers[filter] = trigger; + changeToken = new TestFileChangeToken(); + _fileTriggers[filter] = changeToken; } - return trigger; + return changeToken; } - public TestFileTrigger GetTrigger(string filter) + public TestFileChangeToken GetChangeToken(string filter) { return _fileTriggers[filter]; } diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestFileTrigger.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestFileTrigger.cs deleted file mode 100644 index 469431e581..0000000000 --- a/test/Microsoft.AspNet.Mvc.TestCommon/TestFileTrigger.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; - -namespace Microsoft.Framework.Caching -{ - internal class TestFileTrigger : IExpirationTrigger - { - public bool ActiveExpirationCallbacks { get; } = false; - - public bool IsExpired { get; set; } - - public IDisposable RegisterExpirationCallback(Action callback, object state) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/test/WebSites/HtmlGenerationWebSite/Components/ProductsViewComponent.cs b/test/WebSites/HtmlGenerationWebSite/Components/ProductsViewComponent.cs index a6bebeecf0..736054c014 100644 --- a/test/WebSites/HtmlGenerationWebSite/Components/ProductsViewComponent.cs +++ b/test/WebSites/HtmlGenerationWebSite/Components/ProductsViewComponent.cs @@ -2,8 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Mvc; -using Microsoft.Framework.Caching; using Microsoft.Framework.Caching.Memory; +using Microsoft.Framework.Primitives; namespace HtmlGenerationWebSite.Components { @@ -24,9 +24,9 @@ namespace HtmlGenerationWebSite.Components string products; if (!Cache.TryGetValue(category, out products)) { - IExpirationTrigger trigger; - products = ProductsService.GetProducts(category, out trigger); - Cache.Set(category, products, new MemoryCacheEntryOptions().AddExpirationTrigger(trigger)); + IChangeToken changeToken; + products = ProductsService.GetProducts(category, out changeToken); + Cache.Set(category, products, new MemoryCacheEntryOptions().AddExpirationToken(changeToken)); } ViewData["Products"] = products; diff --git a/test/WebSites/HtmlGenerationWebSite/ProductsService.cs b/test/WebSites/HtmlGenerationWebSite/ProductsService.cs index e4d328b8c1..bf053b84f5 100644 --- a/test/WebSites/HtmlGenerationWebSite/ProductsService.cs +++ b/test/WebSites/HtmlGenerationWebSite/ProductsService.cs @@ -2,7 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading; -using Microsoft.Framework.Caching; +using Microsoft.Framework.Primitives; namespace HtmlGenerationWebSite { @@ -10,11 +10,11 @@ namespace HtmlGenerationWebSite { private readonly CancellationTokenSource _tokenSource = new CancellationTokenSource(); - public string GetProducts(string category, out IExpirationTrigger trigger) + public string GetProducts(string category, out IChangeToken changeToken) { - var token = _tokenSource.IsCancellationRequested ? CancellationToken.None : - _tokenSource.Token; - trigger = new CancellationTokenTrigger(token); + var token = _tokenSource.IsCancellationRequested ? + CancellationToken.None : _tokenSource.Token; + changeToken = new CancellationChangeToken(token); if (category == "Books") { return "Book1, Book2";