Skip to content

Commit 595e473

Browse files
authored
feat: add support for .NET SDK V4 (#61)
1 parent 877029b commit 595e473

File tree

12 files changed

+94
-23
lines changed

12 files changed

+94
-23
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "AWS.AspNetCore.DistributedCacheProvider",
5+
"Type": "Major",
6+
"ChangelogMessages": [
7+
"Updated the .NET SDK dependencies to the latest version 4.0.0-preview.4",
8+
"Marked project as trimmable",
9+
"Added SourceLink support"
10+
]
11+
}
12+
]
13+
}

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1-
# Changelog
1+
## Release 2024-04-20
22

3-
## 0.9.3 (2024-04-20)
3+
### AWS.AspNetCore.DistributedCacheProvider (0.9.3)
44
- Update User-Agent string
55

6-
## 0.9.2 (2023-07-28)
6+
## Release 2023-07-28
7+
8+
### AWS.AspNetCore.DistributedCacheProvider (0.9.2)
79
- Add PackageReadmeFile attribute to show README file in NuGet
810

9-
## 0.9.1 (2023-07-28)
11+
## Release 2023-07-28
12+
13+
### AWS.AspNetCore.DistributedCacheProvider (0.9.1)
1014
- Added the repository README file to the NuGet package
1115

12-
## 0.9.0 (2023-07-06)
16+
## Release 2023-07-06
17+
18+
### AWS.AspNetCore.DistributedCacheProvider (0.9.0)
1319
- Initial preview release

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,42 @@ To send us a pull request, please:
3939
GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and
4040
[creating a pull request](https://help.github.com/articles/creating-a-pull-request/).
4141

42+
## Adding a `change file` to your contribution branch
43+
Each contribution branch should include a `change file` that contains a changelog message for each project that has been updated, as well as the type of increment to perform for those changes when versioning the project.
44+
A `change file` looks like the following example:
45+
```json
46+
{
47+
"Projects": [
48+
{
49+
"Name": "AWS.AspNetCore.DistributedCacheProvider",
50+
"Type": "Patch",
51+
"ChangelogMessages": [
52+
"Fixed an issue causing a failure somewhere"
53+
]
54+
}
55+
]
56+
}
57+
```
58+
The `change file` lists all the modified projects, the changelog message for each project as well as the increment type.
59+
These files are located in the repo at .autover/changes/
60+
You can use the `AutoVer` tool to create the change file. You can install it using the following command:
61+
```
62+
dotnet tool install -g AutoVer
63+
```
64+
You can create the `change file` using the following command:
65+
```
66+
autover change --project-name "AWS.AspNetCore.DistributedCacheProvider" -m "Fixed an issue causing a failure somewhere
67+
```
68+
Note: Make sure to run the command from the root of the repository.
69+
You can update the command to specify which project you are updating.
70+
The available projects are:
71+
* AWS.AspNetCore.DistributedCacheProvider
72+
The possible increment types are:
73+
* Patch
74+
* Minor
75+
* Major
76+
Note: You do not need to create a new `change file` for every changelog message or project within your branch. You can create one `change file` that contains all the modified projects and the changelog messages.
77+
4278

4379
## Finding contributions to work on
4480
Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start.

SampleApp/SampleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>

buildtools/ci.buildspec.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 0.2
33
phases:
44
install:
55
runtime-versions:
6-
dotnet: 6.x
6+
dotnet: 8.x
77
build:
88
commands:
99
- dotnet test --verbosity normal AWS.DistributedCacheProvider.sln --configuration Release --logger trx --results-directory ./testresults

src/AWS.DistributedCacheProvider/AWS.DistributedCacheProvider.csproj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
55
<RootNamespace>AWS.DistributedCacheProvider</RootNamespace>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
8-
<Version>0.9.3</Version>
8+
<Version>2.0.0-preview.1</Version>
99
<PackageId>AWS.AspNetCore.DistributedCacheProvider</PackageId>
1010
<Title>AWS Provider for ASP.NET Core's IDistributedCache</Title>
1111
<Description>The AWS Distributed Cache provider provides an IDistributedCache implementation backed by DynamoDB.</Description>
@@ -20,7 +20,16 @@
2020
<SignAssembly>true</SignAssembly>
2121
<AssemblyOriginatorKeyFile>..\..\public.snk</AssemblyOriginatorKeyFile>
2222

23-
<PackageReadmeFile>README.md</PackageReadmeFile>
23+
<PackageReadmeFile>README.md</PackageReadmeFile>
24+
25+
<EmbedUntrackedSources>true</EmbedUntrackedSources>
26+
<PublishRepositoryUrl>true</PublishRepositoryUrl>
27+
<IncludeSymbols>true</IncludeSymbols>
28+
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
29+
</PropertyGroup>
30+
31+
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
32+
<IsTrimmable>true</IsTrimmable>
2433
</PropertyGroup>
2534

2635
<ItemGroup>
@@ -35,8 +44,9 @@
3544
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
3645
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
3746
<PackageReference Include="Microsoft.Extensions.Options" Version="6.0.0" />
38-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.302.15" />
39-
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="3.7.300" />
47+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0-preview.4" />
48+
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0-preview.4" />
49+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
4050
</ItemGroup>
4151

4252
</Project>

src/AWS.DistributedCacheProvider/DynamoDBDistributedCache.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,6 @@ private DateTimeOffset UnixSecondsToDateTimeOffset(string seconds)
392392
return DateTimeOffset.FromUnixTimeSeconds((long)double.Parse(seconds));
393393
}
394394

395-
396-
397395
/// <summary>
398396
/// Retrieves the value associated with <paramref name="key"/> in the cache and updates the Item's TTL.
399397
/// If there is no value associated with the <paramref name="key"/> or there is a value, but the Item's TTL
@@ -429,6 +427,12 @@ private DateTimeOffset UnixSecondsToDateTimeOffset(string seconds)
429427
throw new DynamoDBDistributedCacheException($"Failed to get Item with key {key}. Caused by {e.Message}", e);
430428
}
431429

430+
if (getItemResponse.Item is null)
431+
{
432+
_logger.LogDebug("DynamoDB did not find an Item associated with the key {key}", key);
433+
return null;
434+
}
435+
432436
//Check if there is a value we should be returning to the client. If there is no value, there is no reason to refresh the Item
433437
if (getItemResponse.Item.ContainsKey(VALUE_KEY))
434438
{

src/AWS.DistributedCacheProvider/Internal/DynamoDBCacheProviderHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static AttributeValue CalculateTTL(DistributedCacheEntryOptions options)
6464
var ttl = DateTimeOffset.UtcNow.Add(((TimeSpan)options.SlidingExpiration));
6565
//Cannot be later than the deadline
6666
var absoluteTTL = CalculateTTLDeadline(options);
67-
if (absoluteTTL.NULL)
67+
if (absoluteTTL.NULL is not null && (bool)absoluteTTL.NULL)
6868
{
6969
return new AttributeValue { N = ttl.ToUnixTimeSeconds().ToString() };
7070
}

src/AWS.DistributedCacheProvider/Internal/DynamoDBTableCreator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public async Task<string> CreateTableIfNotExistsAsync(IAmazonDynamoDB client, st
7272
private string ValidateTable(TableDescription description)
7373
{
7474
var partitionKeyName = "";
75-
foreach (var key in description.KeySchema)
75+
var keySchema = description.KeySchema ?? new List<KeySchemaElement>();
76+
foreach (var key in keySchema)
7677
{
7778
if (key.KeyType.Equals(KeyType.RANGE))
7879
{
@@ -81,7 +82,8 @@ private string ValidateTable(TableDescription description)
8182
}
8283
else //We know the key is of type Hash
8384
{
84-
foreach (var attributeDef in description.AttributeDefinitions)
85+
var attributeDefinitions = description.AttributeDefinitions ?? new List<AttributeDefinition>();
86+
foreach (var attributeDef in attributeDefinitions)
8587
{
8688
if (attributeDef.AttributeName.Equals(key.AttributeName) && attributeDef.AttributeType != ScalarAttributeType.S)
8789
{

test/AWS.DistributedCacheProviderIntegrationTests/AWS.DistributedCacheProviderIntegrationTests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net6.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

88
<IsPackable>false</IsPackable>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.7.302.15" />
13-
<PackageReference Include="AWSSDK.SecurityToken" Version="3.7.300.75" />
12+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="4.0.0-preview.4" />
13+
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.0-preview.4" />
1414
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
1515
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
1616
<PackageReference Include="xunit" Version="2.4.2" />

0 commit comments

Comments
 (0)