Skip to content

Merge develop to master #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0d0f0e3
Added support for a cache key provider for InMemoryCacheHandler
Jan 25, 2022
4244abc
Added cache key provider MethodUriHeadersCacheKeysProvider; added uni…
Jan 25, 2022
38fa1c8
Readme.md update
Jan 25, 2022
55110ee
Update README.md
steuic Jan 26, 2022
d3b3b3e
Delimited test related to MethodUriHeadersCacheKeysProvider in a spec…
Jan 26, 2022
0c63522
Added query sting to example in MethodUriHeadersCacheKeysProvider
Jan 28, 2022
f5bddd8
Add editorconfig file
Mar 10, 2022
0eb1cd5
Add unit tests for cache key providers
Mar 11, 2022
2d38f41
Extend unit tests with more cases
thomasgalliker Mar 11, 2022
5339664
Update sample project
thomasgalliker Mar 11, 2022
d4b967d
Update traget frameworks
thomasgalliker Apr 7, 2022
61f612d
Update year
thomasgalliker Apr 7, 2022
fa55191
Cleanup code
thomasgalliker Apr 7, 2022
048f212
Code cleanup
thomasgalliker Apr 7, 2022
1bddecd
Remove empty headers HEA_;
thomasgalliker May 7, 2022
09a9091
Merge pull request #10 from steuic/develop
thomasgalliker May 7, 2022
c8f96da
Update project files + target frameworks
thomasgalliker May 7, 2022
e63e78f
Bump version
thomasgalliker May 7, 2022
a3d7515
Update target frameworks
thomasgalliker May 7, 2022
286f49c
Migrate wpf app to packagereference
thomasgalliker May 7, 2022
f501a12
Update build configuration to windows-2022 + add code coverage
thomasgalliker May 7, 2022
058ae09
Rename build.yml to azure-pipelines.yml
thomasgalliker May 7, 2022
aca58ed
Remove legacy wpf sample
thomasgalliker May 7, 2022
3cfdb0f
Run automatic code cleanup
thomasgalliker May 7, 2022
500953d
Update readme
thomasgalliker May 7, 2022
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
147 changes: 147 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
####################################################################
# Editor Configuration (Updated 2022-01-07)
#
# (c)2021 superdev GmbH
####################################################################

root = true

[*.cs]
csharp_indent_block_contents = true
csharp_indent_braces = false
csharp_indent_case_contents = true
csharp_indent_labels = one_less_than_current
csharp_indent_switch_labels = true

csharp_new_line_before_catch = true
csharp_new_line_before_else = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_open_brace = all
csharp_new_line_between_query_expression_clauses = true

csharp_prefer_braces = true:error
csharp_prefer_simple_default_expression = true:error
csharp_prefer_simple_using_statement = false

csharp_preserve_single_line_blocks = true
csharp_preserve_single_line_statements = false

csharp_space_after_cast = false
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_after_comma = true
csharp_space_after_dot = false

csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_after_semicolon_in_for_statement = true
csharp_space_around_binary_operators = before_and_after
csharp_space_around_declaration_statements = do_not_ignore
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_before_comma = false
csharp_space_before_dot = false
csharp_space_before_open_square_brackets = false
csharp_space_before_semicolon_in_for_statement = false
csharp_space_between_empty_square_brackets = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_declaration_name_and_open_parenthesis = false
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_parentheses = none
csharp_space_between_square_brackets = false

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:none
csharp_style_expression_bodied_constructors = false:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_lambdas = true:none
csharp_style_expression_bodied_local_functions = false
csharp_style_expression_bodied_methods = false:none
csharp_style_expression_bodied_operators = false:none
csharp_style_expression_bodied_properties = true:silent

csharp_style_conditional_delegate_call = true:error
csharp_style_inlined_variable_declaration = true:error
csharp_style_pattern_matching_over_as_with_null_check = true:error
csharp_style_pattern_matching_over_is_with_cast_check = true:error
csharp_style_throw_expression = true:suggestion
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:error
csharp_style_implicit_object_creation_when_type_is_apparent = false
csharp_style_prefer_switch_expression = false

dotnet_sort_system_directives_first = true
dotnet_style_coalesce_expression = true:error
dotnet_style_collection_initializer = true:error
dotnet_style_explicit_tuple_names = true:error
dotnet_style_null_propagation = true:error
dotnet_style_object_initializer = true:none
dotnet_style_predefined_type_for_locals_parameters_members = true:error
dotnet_style_predefined_type_for_member_access = true:error

dotnet_style_qualification_for_event = true:error
dotnet_style_qualification_for_field = true:error
dotnet_style_qualification_for_method = true:error
dotnet_style_qualification_for_property = true:error

end_of_line = crlf
indent_size = 4
indent_style = space
insert_final_newline = false
tab_width = 4

dotnet_naming_symbols.private_field_symbol.applicable_kinds = field
dotnet_naming_symbols.private_field_symbol.applicable_accessibilities = private
dotnet_naming_style.private_field_style.capitalization = camel_case
dotnet_naming_rule.private_fields_are_camel_case.severity = error
dotnet_naming_rule.private_fields_are_camel_case.symbols = private_field_symbol
dotnet_naming_rule.private_fields_are_camel_case.style = private_field_style

dotnet_naming_symbols.non_private_field_symbol.applicable_kinds = field
dotnet_naming_symbols.non_private_field_symbol.applicable_accessibilities = public,internal,friend,protected,protected_internal,protected_friend
dotnet_naming_style.non_private_field_style.capitalization = pascal_case
dotnet_naming_rule.non_private_fields_are_pascal_case.severity = error
dotnet_naming_rule.non_private_fields_are_pascal_case.symbols = non_private_field_symbol
dotnet_naming_rule.non_private_fields_are_pascal_case.style = non_private_field_style

dotnet_naming_symbols.parameter_symbol.applicable_kinds = parameter
dotnet_naming_style.parameter_style.capitalization = camel_case
dotnet_naming_rule.parameters_are_camel_case.severity = error
dotnet_naming_rule.parameters_are_camel_case.symbols = parameter_symbol
dotnet_naming_rule.parameters_are_camel_case.style = parameter_style

dotnet_naming_symbols.non_interface_type_symbol.applicable_kinds = class,struct,enum,delegate
dotnet_naming_style.non_interface_type_style.capitalization = pascal_case
dotnet_naming_rule.non_interface_types_are_pascal_case.severity = error
dotnet_naming_rule.non_interface_types_are_pascal_case.symbols = non_interface_type_symbol
dotnet_naming_rule.non_interface_types_are_pascal_case.style = non_interface_type_style

dotnet_naming_symbols.interface_type_symbol.applicable_kinds = interface
dotnet_naming_style.interface_type_style.capitalization = pascal_case
dotnet_naming_style.interface_type_style.required_prefix = I
dotnet_naming_rule.interface_types_must_be_prefixed_with_I.severity = error
dotnet_naming_rule.interface_types_must_be_prefixed_with_I.symbols = interface_type_symbol
dotnet_naming_rule.interface_types_must_be_prefixed_with_I.style = interface_type_style

dotnet_naming_symbols.member_symbol.applicable_kinds = method,property,event
dotnet_naming_style.member_style.capitalization = pascal_case
dotnet_naming_rule.members_are_pascal_case.severity = error
dotnet_naming_rule.members_are_pascal_case.symbols = member_symbol
dotnet_naming_rule.members_are_pascal_case.style = member_style

dotnet_naming_rule.static_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_pascal_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_pascal_case.style = static_field_style
dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.applicable_accessibilities = *
dotnet_naming_symbols.static_fields.required_modifiers = static
dotnet_naming_style.static_field_style.capitalization = pascal_case

# CS4014: Because this call is not awaited, execution of the current method continues before the call is completed
dotnet_diagnostic.CS4014.severity = error

# IDE0051: Remove unused private members
dotnet_diagnostic.IDE0051.severity = warning
15 changes: 5 additions & 10 deletions HttpClient.Caching.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2011
# Visual Studio Version 17
VisualStudioVersion = 17.1.32421.90
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClient.Caching", "HttpClient.Caching\HttpClient.Caching.csproj", "{CBA31ECF-3D41-4AF0-B966-7815F2AD25E9}"
EndProject
Expand All @@ -11,16 +11,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClient.Caching.Tests",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{755C7AC9-B66F-4FB3-9CFB-A6013586A5F7}"
ProjectSection(SolutionItems) = preProject
build.yml = build.yml
.editorconfig = .editorconfig
.gitignore = .gitignore
azure-pipelines.yml = azure-pipelines.yml
README.md = README.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAppSample", "Samples\ConsoleAppSample\ConsoleAppSample.csproj", "{592B2324-79AA-4973-8CE5-F65BD503641F}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{2AB15A56-D5AC-4CBB-95BF-241051541E52}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfSample", "Samples\WpfSample\WpfSample.csproj", "{750EA219-7FAB-44F6-B909-BC678CFF4BE4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -39,18 +39,13 @@ Global
{592B2324-79AA-4973-8CE5-F65BD503641F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{592B2324-79AA-4973-8CE5-F65BD503641F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{592B2324-79AA-4973-8CE5-F65BD503641F}.Release|Any CPU.Build.0 = Release|Any CPU
{750EA219-7FAB-44F6-B909-BC678CFF4BE4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{750EA219-7FAB-44F6-B909-BC678CFF4BE4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{750EA219-7FAB-44F6-B909-BC678CFF4BE4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{750EA219-7FAB-44F6-B909-BC678CFF4BE4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{D8F20DC2-E69A-4432-A68B-FD4A8232BA43} = {82C933E0-5F3A-46DD-BE18-233590F11503}
{592B2324-79AA-4973-8CE5-F65BD503641F} = {2AB15A56-D5AC-4CBB-95BF-241051541E52}
{750EA219-7FAB-44F6-B909-BC678CFF4BE4} = {2AB15A56-D5AC-4CBB-95BF-241051541E52}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {46294172-BC59-4710-8105-CF322C619EA8}
Expand Down
8 changes: 4 additions & 4 deletions HttpClient.Caching/Abstractions/CacheDataExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public static class CacheDataExtensions
{
public static byte[] Serialize(this CacheData cacheData)
{
string json = JsonConvert.SerializeObject(cacheData);
byte[] bytes = new byte[json.Length * sizeof(char)];
var json = JsonConvert.SerializeObject(cacheData);
var bytes = new byte[json.Length * sizeof(char)];
Buffer.BlockCopy(json.ToCharArray(), 0, bytes, 0, bytes.Length);
return bytes;
}
Expand All @@ -17,9 +17,9 @@ public static CacheData Deserialize(this byte[] cacheData)
{
try
{
char[] chars = new char[cacheData.Length / sizeof(char)];
var chars = new char[cacheData.Length / sizeof(char)];
Buffer.BlockCopy(cacheData, 0, chars, 0, cacheData.Length);
string json = new string(chars);
var json = new string(chars);
var data = JsonConvert.DeserializeObject<CacheData>(json);
return data;
}
Expand Down
31 changes: 13 additions & 18 deletions HttpClient.Caching/Abstractions/CacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ public static class CacheExtensions
{
public static object Get(this IMemoryCache cache, object key)
{
object obj = null;
cache.TryGetValue(key, out obj);
cache.TryGetValue(key, out var obj);
return obj;
}

public static TItem Get<TItem>(this IMemoryCache cache, object key)
{
TItem obj;
cache.TryGetValue(key, out obj);
cache.TryGetValue(key, out TItem obj);
return obj;
}

public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out TItem value)
{
object obj;
if (cache.TryGetValue(key, out obj))
if (cache.TryGetValue(key, out var obj))
{
value = (TItem)obj;
return true;
Expand All @@ -35,15 +32,15 @@ public static bool TryGetValue<TItem>(this IMemoryCache cache, object key, out T

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value)
{
ICacheEntry entry = cache.CreateEntry(key);
var entry = cache.CreateEntry(key);
entry.Value = value;
entry.Dispose();
return value;
}

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, DateTimeOffset absoluteExpiration)
{
ICacheEntry entry = cache.CreateEntry(key);
var entry = cache.CreateEntry(key);
DateTimeOffset? nullable = absoluteExpiration;
entry.AbsoluteExpiration = nullable;
entry.Value = value;
Expand All @@ -53,7 +50,7 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, TimeSpan absoluteExpirationRelativeToNow)
{
ICacheEntry entry = cache.CreateEntry(key);
var entry = cache.CreateEntry(key);
TimeSpan? nullable = absoluteExpirationRelativeToNow;
entry.AbsoluteExpirationRelativeToNow = nullable;
entry.Value = value;
Expand All @@ -63,8 +60,8 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, IChangeToken expirationToken)
{
ICacheEntry entry = cache.CreateEntry(key);
IChangeToken expirationToken1 = expirationToken;
var entry = cache.CreateEntry(key);
var expirationToken1 = expirationToken;
entry.AddExpirationToken(expirationToken1);
entry.Value = value;
entry.Dispose();
Expand All @@ -73,7 +70,7 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,

public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value, MemoryCacheEntryOptions options)
{
using (ICacheEntry entry = cache.CreateEntry(key))
using (var entry = cache.CreateEntry(key))
{
if (options != null)
{
Expand All @@ -88,10 +85,9 @@ public static TItem Set<TItem>(this IMemoryCache cache, object key, TItem value,

public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, TItem> factory)
{
object obj;
if (!cache.TryGetValue(key, out obj))
if (!cache.TryGetValue(key, out var obj))
{
ICacheEntry entry = cache.CreateEntry(key);
var entry = cache.CreateEntry(key);
obj = factory(entry);
entry.SetValue(obj);
entry.Dispose();
Expand All @@ -102,10 +98,9 @@ public static TItem GetOrCreate<TItem>(this IMemoryCache cache, object key, Func

public static async Task<TItem> GetOrCreateAsync<TItem>(this IMemoryCache cache, object key, Func<ICacheEntry, Task<TItem>> factory)
{
object obj;
if (!cache.TryGetValue(key, out obj))
if (!cache.TryGetValue(key, out var obj))
{
ICacheEntry entry = cache.CreateEntry(key);
var entry = cache.CreateEntry(key);
obj = await factory(entry);
entry.SetValue(obj);
entry.Dispose();
Expand Down
17 changes: 17 additions & 0 deletions HttpClient.Caching/Abstractions/ICacheKeysProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Net.Http;

namespace Microsoft.Extensions.Caching.Abstractions
{
/// <summary>
/// Provides keys to store or retrieve data in the cache
/// </summary>
public interface ICacheKeysProvider
{
/// <summary>
/// Return the key for the request message <paramref name="request"/>
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
string GetKey(HttpRequestMessage request);
}
}
5 changes: 2 additions & 3 deletions HttpClient.Caching/Abstractions/StatusCodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ public static class StatusCodeExtensions
/// <returns>A TimeSpan that should be used for the given status code when putting it into the cache.</returns>
public static TimeSpan GetAbsoluteExpirationRelativeToNow(this HttpStatusCode statusCode, IDictionary<HttpStatusCode, TimeSpan> mapping)
{
int code = (int)statusCode;
TimeSpan expiration;
var code = (int)statusCode;

// get the expiration settings for the given status code
if (mapping.TryGetValue(statusCode, out expiration))
if (mapping.TryGetValue(statusCode, out var expiration))
{
return expiration;
}
Expand Down
Loading