Skip to content

Commit 1f8ca76

Browse files
committed
Http Cache incorrect response after edit file multiple times #175
1 parent 255f07e commit 1f8ca76

3 files changed

Lines changed: 12 additions & 17 deletions

File tree

examples/HttpServer/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ static void Main(string[] args)
171171

172172
// Create a new HTTP server
173173
var server = new HttpCacheServer(IPAddress.Any, port);
174-
server.AddStaticContent(www, "/api");
174+
server.AddStaticContent(www, "/");
175175

176176
// Start the server
177177
Console.Write("Server starting...");

source/NetCoreServer/FileCache.cs

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,8 @@ private static bool IsDirectory(string path)
242242

243243
private static void OnCreated(object sender, FileSystemEventArgs e, FileCache cache, FileCacheEntry entry)
244244
{
245-
var key = e.FullPath.Replace(entry._path, entry._prefix);
246-
var file = e.FullPath;
245+
var key = e.FullPath.Replace('\\', '/').Replace(entry._path + "/", entry._prefix);
246+
var file = e.FullPath.Replace('\\', '/');
247247

248248
// Skip missing files
249249
if (!File.Exists(file))
@@ -260,8 +260,8 @@ private static void OnChanged(object sender, FileSystemEventArgs e, FileCache ca
260260
if (e.ChangeType != WatcherChangeTypes.Changed)
261261
return;
262262

263-
var key = e.FullPath.Replace(entry._path, entry._prefix);
264-
var file = e.FullPath;
263+
var key = e.FullPath.Replace('\\', '/').Replace(entry._path + "/", entry._prefix);
264+
var file = e.FullPath.Replace('\\', '/');
265265

266266
// Skip missing files
267267
if (!File.Exists(file))
@@ -275,18 +275,18 @@ private static void OnChanged(object sender, FileSystemEventArgs e, FileCache ca
275275

276276
private static void OnDeleted(object sender, FileSystemEventArgs e, FileCache cache, FileCacheEntry entry)
277277
{
278-
var key = e.FullPath.Replace(entry._path, entry._prefix);
279-
var file = e.FullPath;
278+
var key = e.FullPath.Replace('\\', '/').Replace(entry._path + "/", entry._prefix);
279+
var file = e.FullPath.Replace('\\', '/');
280280

281281
cache.RemoveFileInternal(entry._path, key);
282282
}
283283

284284
private static void OnRenamed(object sender, RenamedEventArgs e, FileCache cache, FileCacheEntry entry)
285285
{
286-
var oldKey = e.OldFullPath.Replace(entry._path, entry._prefix);
287-
var oldFile = e.OldFullPath;
288-
var newKey = e.FullPath.Replace(entry._path, entry._prefix);
289-
var newFile = e.FullPath;
286+
var oldKey = e.OldFullPath.Replace('\\', '/').Replace(entry._path + "/", entry._prefix);
287+
var oldFile = e.OldFullPath.Replace('\\', '/');
288+
var newKey = e.FullPath.Replace('\\', '/').Replace(entry._path + "/", entry._prefix);
289+
var newFile = e.FullPath.Replace('\\', '/');
290290

291291
// Skip missing files
292292
if (!File.Exists(newFile))
@@ -304,9 +304,6 @@ private bool InsertFileInternal(string path, string file, string key, TimeSpan t
304304
{
305305
try
306306
{
307-
key = key.Replace('\\', '/');
308-
file = file.Replace('\\', '/');
309-
310307
// Load the cache file content
311308
var content = File.ReadAllBytes(file);
312309
if (!handler(this, key, content, timeout))
@@ -327,8 +324,6 @@ private bool RemoveFileInternal(string path, string key)
327324
{
328325
try
329326
{
330-
key = key.Replace('\\', '/');
331-
332327
using (new WriteLock(_lockEx))
333328
{
334329
// Update entries by path map

source/NetCoreServer/NetCoreServer.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net6.0</TargetFramework>
5-
<Version>6.1.0.0</Version>
5+
<Version>6.2.0.0</Version>
66
<Authors>Ivan Shynkarenka</Authors>
77
<Copyright>Copyright (c) 2019-2022 Ivan Shynkarenka</Copyright>
88
<RepositoryUrl>https://github.com/chronoxor/NetCoreServer</RepositoryUrl>

0 commit comments

Comments
 (0)