Skip to content

Commit a8ea942

Browse files
committed
Include the running application name as part of the default temp path
1 parent 4b48ff3 commit a8ea942

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/HttpClient.Cache/Files/FileCache.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Net;
2+
using System.Reflection;
23

34
namespace HttpClientCache.Files;
45

@@ -15,6 +16,8 @@ public class FileCache : IHttpCache
1516

1617
public static FileCache Default { get; } = new();
1718

19+
public DirectoryInfo RootDirectory => _rootDirectory;
20+
1821
/// <summary>
1922
/// Gets or sets the maximum number of cache entries allowed in the cache directory.
2023
/// Note that this is a soft limit, and the actual number of entries may exceed this value temporarily during purging.
@@ -35,7 +38,13 @@ public class FileCache : IHttpCache
3538
/// Creates a new instance of <see cref="FileCache"/> with the default root directory.
3639
/// </summary>
3740
public FileCache()
38-
: this(Path.Combine(Path.GetTempPath(), "HttpClient.Cache.Files.FileCache")) { }
41+
: this(
42+
Path.Combine(
43+
Path.GetTempPath(),
44+
"HttpClient.FileCache",
45+
Assembly.GetEntryAssembly()!.GetName().Name!
46+
)
47+
) { }
3948

4049
/// <summary>
4150
/// Creates a new instance of <see cref="FileCache"/> with the specified root directory.

test/HttpClient.Cache.Tests/File/FileCacheTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ public void Dispose()
2828
Assert.Empty(_rootDirectory.EnumerateFiles("*.*", SearchOption.AllDirectories));
2929
}
3030

31+
[Fact]
32+
public void DefaultRootDirectory()
33+
{
34+
// Given
35+
var cache = new FileCache();
36+
37+
// When
38+
var rootDirectory = cache.RootDirectory;
39+
40+
// Then
41+
Assert.Equal(
42+
Path.Combine(Path.GetTempPath(), "HttpClient.FileCache", "HttpClient.Cache.Tests"),
43+
rootDirectory.FullName
44+
);
45+
}
46+
3147
[Fact]
3248
public async Task Get_KeyDoesNotExist()
3349
{

0 commit comments

Comments
 (0)