Skip to content

Commit 3711f8b

Browse files
authored
Merge pull request #11 from Leefrost/icon-fix
Added missed icon
2 parents 3b4496c + dafbf10 commit 3711f8b

File tree

4 files changed

+103
-11
lines changed

4 files changed

+103
-11
lines changed

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Setup .NET
3131
uses: actions/setup-dotnet@v3
3232

33-
- run: dotnet pack --configuration Release --output ${{ env.NuGetDirectory }}
33+
- run: dotnet pack .\src\HttpClient.Cache\HttpClient.Cache.csproj --configuration Release --output ${{ env.NuGetDirectory }}
3434

3535
- uses: actions/upload-artifact@v3
3636
with:

src/HttpClient.Cache/HttpClient.Cache.csproj

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,40 @@
77
</PropertyGroup>
88

99
<PropertyGroup>
10-
<Authors>Sergii Lischuk</Authors>
11-
<Description>A simple and easy cache for HttpClient</Description>
12-
<PackageProjectUrl>https://codestory.me</PackageProjectUrl>
13-
<PackageTags>cache, httpclient, library</PackageTags>
14-
15-
<GenerateDocumentationFile>True</GenerateDocumentationFile>
16-
<NoWarn>$(NoWarn);CS1591</NoWarn>
1710
<EnablePackageValidation>true</EnablePackageValidation>
11+
1812
<!-- Optional: Detect breaking changes from a previous version -->
1913
<!-- <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion> -->
2014
</PropertyGroup>
2115

16+
<ItemGroup>
17+
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
18+
<PrivateAssets>all</PrivateAssets>
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
20+
</PackageReference>
21+
</ItemGroup>
22+
2223
<PropertyGroup>
23-
<PackageLicenseExpression>MIT</PackageLicenseExpression>
24+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
25+
26+
<!-- If all members are not documented, you can disable the compiler warnings -->
27+
<NoWarn>$(NoWarn);CS1591</NoWarn>
2428
</PropertyGroup>
2529

2630
<PropertyGroup>
27-
<PackageReadmeFile>README.md</PackageReadmeFile>
31+
<Authors>Sergii Lischuk</Authors>
32+
<Description>A simple and easy cache for HttpClient</Description>
33+
34+
<!-- PackageProjectUrl is different from the repository URL. It can be a documentation
35+
website or a website explaining the project -->
36+
<PackageProjectUrl>https://codestory.me</PackageProjectUrl>
37+
38+
<!-- A list of tags to help the search engine to understand the content of the package -->
39+
<PackageTags>cache, httpclient, library</PackageTags>
40+
</PropertyGroup>
41+
42+
<PropertyGroup>
43+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2844
</PropertyGroup>
2945

3046
<PropertyGroup>
@@ -35,11 +51,19 @@
3551
<None Include="icon.png" Pack="true" PackagePath="" />
3652
</ItemGroup>
3753

54+
<PropertyGroup>
55+
<PackageReadmeFile>README.md</PackageReadmeFile>
56+
</PropertyGroup>
57+
3858
<ItemGroup>
39-
<None Include="README.md" Pack="true" PackagePath="" />
59+
<None Include="README.md" Pack="true" PackagePath=""/>
4060
</ItemGroup>
4161

4262
<ItemGroup>
63+
<PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1">
64+
<PrivateAssets>all</PrivateAssets>
65+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
66+
</PackageReference>
4367
<PackageReference Include="MinVer" Version="4.3.0">
4468
<PrivateAssets>all</PrivateAssets>
4569
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

src/HttpClient.Cache/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# HttpClient.Cache
2+
3+
A caching wrapper around HttpClient to cache responses
4+
5+
### The Purpose
6+
7+
Working with some high load systems or with system where is important to have good response time
8+
cache is a first one citizen.
9+
10+
### Install
11+
12+
//TODO Nuget deployment
13+
14+
```shell
15+
foo@bar:~$ Install-Package HttpClient.Cache
16+
```
17+
18+
### Examples
19+
20+
```csharp
21+
const string url = "http://worldclockapi.com/api/json/utc/now";
22+
23+
//Set the cache time for each required status
24+
var cacheExpiration = new Dictionary<HttpStatusCode, TimeSpan>
25+
{
26+
{HttpStatusCode.OK, TimeSpan.FromSeconds(60)},
27+
{HttpStatusCode.BadRequest, TimeSpan.FromSeconds(10)},
28+
{HttpStatusCode.InternalServerError, TimeSpan.FromSeconds(5)}
29+
};
30+
31+
//Client calls API and caches it
32+
//Report will show 1 Miss (initial) and 4 Hits.
33+
var innerHandler = new HttpClientHandler();
34+
var cacheHandler = new InMemoryCacheHandler(innerHandler, cacheExpiration);
35+
using (var httpClient = new System.Net.Http.HttpClient(cacheHandler))
36+
{
37+
for (int i = 1; i <= 5; ++i)
38+
{
39+
Console.Write($"Try: {i}: {url} ");
40+
41+
var stopwatch = Stopwatch.StartNew();
42+
var result = await httpClient.GetAsync(url);
43+
Console.Write($" --> {result.StatusCode} ");
44+
stopwatch.Stop();
45+
46+
Console.WriteLine($"Done in: {stopwatch.ElapsedMilliseconds} ms");
47+
await Task.Delay(TimeSpan.FromSeconds(1));
48+
}
49+
}
50+
51+
var stats = cacheHandler.StatsProvider.GetReport();
52+
Console.WriteLine($"Cache stats - total requests: {stats.Total.TotalRequests}");
53+
Console.WriteLine($"--> Hit: {stats.Total.CacheHit} [{stats.Total.TotalHitsPercent}]");
54+
Console.WriteLine($"--> Miss: {stats.Total.CacheMiss} [{stats.Total.TotalMissPercent}]");
55+
Console.ReadLine();
56+
```
57+
Will generate next output:
58+
```console
59+
Try: 1: http://worldclockapi.com/api/json/utc/now --> OK Done in: 450 ms
60+
Try: 2: http://worldclockapi.com/api/json/utc/now --> OK Done in: 57 ms
61+
Try: 3: http://worldclockapi.com/api/json/utc/now --> OK Done in: 0 ms
62+
Try: 4: http://worldclockapi.com/api/json/utc/now --> OK Done in: 0 ms
63+
Try: 5: http://worldclockapi.com/api/json/utc/now --> OK Done in: 0 ms
64+
Cache stats - total requests: 5
65+
--> Hit: 4 [0,8]
66+
--> Miss: 1 [0,2]
67+
68+
```
File renamed without changes.

0 commit comments

Comments
 (0)