Skip to content

Commit 6957f6b

Browse files
committed
Fix file caching in ASP.NET Core. Closes #322
1 parent 86e4da2 commit 6957f6b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/React.AspNet/MemoryFileCacheCore.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace React.AspNet
2323
public class MemoryFileCacheCore : ICache
2424
{
2525
private readonly IMemoryCache _cache;
26-
private readonly IFileProvider _fileProvider;
26+
private readonly IHostingEnvironment _hostingEnv;
2727

2828
/// <summary>
2929
/// Initializes a new instance of the <see cref="MemoryFileCacheCore" /> class.
@@ -33,7 +33,7 @@ public class MemoryFileCacheCore : ICache
3333
public MemoryFileCacheCore(IMemoryCache cache, IHostingEnvironment hostingEnv)
3434
{
3535
_cache = cache;
36-
_fileProvider = hostingEnv.ContentRootFileProvider;
36+
_hostingEnv = hostingEnv;
3737
}
3838

3939
/// <summary>
@@ -84,13 +84,15 @@ public void Set<T>(string key, T data, TimeSpan slidingExpiration, IEnumerable<s
8484
{
8585
foreach (var file in cacheDependencyFiles)
8686
{
87-
options.AddExpirationToken(_fileProvider.Watch(file));
87+
var relativePath = file.Replace(_hostingEnv.WebRootPath, string.Empty).TrimStart('\\', '/');
88+
options.AddExpirationToken(_hostingEnv.WebRootFileProvider.Watch(relativePath));
8889
}
8990
}
9091

9192
if (cacheDependencyKeys != null && cacheDependencyKeys.Any())
9293
{
9394
// https://github.com/aspnet/Docs/issues/1938
95+
// https://github.com/aspnet/Caching/issues/236
9496
throw new NotImplementedException();
9597
}
9698

0 commit comments

Comments
 (0)