Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions HttpClient.Caching.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
README.md = README.md
global.json = global.json
ReleaseNotes.txt = ReleaseNotes.txt
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppSample", "Samples\ConsoleAppSample\ConsoleAppSample.csproj", "{592B2324-79AA-4973-8CE5-F65BD503641F}"
Expand Down
1 change: 0 additions & 1 deletion HttpClient.Caching/Abstractions/CacheData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using System.Net.Http;

namespace Microsoft.Extensions.Caching.Abstractions
Expand Down
28 changes: 15 additions & 13 deletions HttpClient.Caching/Abstractions/CacheDataExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
using System;
using Newtonsoft.Json;
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Extensions.Caching.Internals;

namespace Microsoft.Extensions.Caching.Abstractions
{
public static class CacheDataExtensions
{
private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new CacheDataJsonConverter() }
};

public static byte[] Serialize(this CacheData cacheData)
{
var json = JsonConvert.SerializeObject(cacheData);
var bytes = new byte[json.Length * sizeof(char)];
Buffer.BlockCopy(json.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
return JsonSerializer.SerializeToUtf8Bytes(cacheData, SerializerOptions);
}

public static CacheData Deserialize(this byte[] cacheData)
{
try
{
var chars = new char[cacheData.Length / sizeof(char)];
Buffer.BlockCopy(cacheData, 0, chars, 0, cacheData.Length);
var json = new string(chars);
var data = JsonConvert.DeserializeObject<CacheData>(json);
return data;
return JsonSerializer.Deserialize<CacheData>(cacheData, SerializerOptions)!;
}
catch
{
return null;
return null!;
}
}
}
}
}
113 changes: 0 additions & 113 deletions HttpClient.Caching/Abstractions/CacheExtensions.cs

This file was deleted.

13 changes: 0 additions & 13 deletions HttpClient.Caching/Abstractions/CacheItemPriority.cs

This file was deleted.

12 changes: 0 additions & 12 deletions HttpClient.Caching/Abstractions/EvictionReason.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task<CacheData> ToCacheEntryAsync(this HttpResponseMessage h
return httpResponseMessage.ToCacheEntry(contentBytes);
}

#if NET5_0_OR_GREATER
#if NET8_0_OR_GREATER
public static CacheData ToCacheEntry(this HttpResponseMessage httpResponseMessage)
{
using var contentStream = httpResponseMessage.Content.ReadAsStream();
Expand Down
51 changes: 0 additions & 51 deletions HttpClient.Caching/Abstractions/ICacheEntry.cs

This file was deleted.

4 changes: 2 additions & 2 deletions HttpClient.Caching/Abstractions/ICacheKeysProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface ICacheKeysProvider
/// <summary>
/// Return the key for the request message <paramref name="request"/>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
/// <param name="request">The http request message.</param>
/// <returns>The cache key.</returns>
string GetKey(HttpRequestMessage request);
}
}
26 changes: 0 additions & 26 deletions HttpClient.Caching/Abstractions/IChangeToken.cs

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions HttpClient.Caching/Abstractions/PostEvictionDelegate.cs

This file was deleted.

2 changes: 0 additions & 2 deletions HttpClient.Caching/Abstractions/StatusCodeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;
using System.Collections.Generic;
using System.Net;

namespace Microsoft.Extensions.Caching.Abstractions
Expand Down
Loading