Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion NatsDistributedCache.sln
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PerfTest", "util\PerfTest\P
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadmeExample", "util\ReadmeExample\ReadmeExample.csproj", "{2F16AC9F-97A1-4362-84B4-F03C3EBC6CD6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NatsHybridCache", "src\NatsHybridCache\NatsHybridCache.csproj", "{F95B33FB-37B3-44F4-9E10-55835A527CA3}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NatsHybridCacheExtensions", "src\NatsHybridCacheExtensions\NatsHybridCacheExtensions.csproj", "{F95B33FB-37B3-44F4-9E10-55835A527CA3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
30 changes: 8 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CodeCargo.NatsDistributedCache](https://img.shields.io/nuget/v/CodeCargo.NatsDistributedCache?color=516bf1&label=CodeCargo.NatsDistributedCache)](https://www.nuget.org/packages/CodeCargo.NatsDistributedCache/) [![CodeCargo.NatsHybridCache](https://img.shields.io/nuget/v/CodeCargo.NatsHybridCache?color=516bf1&label=CodeCargo.NatsHybridCache)](https://www.nuget.org/packages/CodeCargo.NatsHybridCache/)
[![CodeCargo.Nats.DistributedCache](https://img.shields.io/nuget/v/CodeCargo.Nats.DistributedCache?color=516bf1&label=CodeCargo.Nats.DistributedCache)](https://www.nuget.org/packages/CodeCargo.Nats.DistributedCache/) [![CodeCargo.Nats.HybridCacheExtensions](https://img.shields.io/nuget/v/CodeCargo.Nats.HybridCacheExtensions?color=516bf1&label=CodeCargo.Nats.HybridCacheExtensions)](https://www.nuget.org/packages/CodeCargo.Nats.HybridCacheExtensions/)

# CodeCargo.NatsDistributedCache
# NATS Distributed Cache

## Overview

Expand All @@ -16,23 +16,9 @@ A .NET 8+ library for using NATS with `HybridCache` or as an `IDistributedCache`
await kvContext.CreateOrUpdateStoreAsync(new NatsKVConfig("cache") { LimitMarkerTTL = TimeSpan.FromSeconds(1) });
```

## Installation

```bash
# add NATS Distributed Cache
dotnet add package CodeCargo.NatsDistributedCache
dotnet add package CodeCargo.NatsHybridCache

# optional - add full NATS.Net (NATS Distributed Cache uses a subset of NATS.Net dependencies)
dotnet add package NATS.Net

# optional - add HybridCache
dotnet add package Microsoft.Extensions.Caching.Hybrid
```

## Use with `HybridCache`

The `CodeCargo.NatsHybridCache` package provides an extension method that:
The `CodeCargo.Nats.HybridCacheExtensions` package provides an extension method that:

1. Adds the NATS `IDistributedCache`
2. Adds `HybridCache`
Expand All @@ -41,15 +27,15 @@ The `CodeCargo.NatsHybridCache` package provides an extension method that:
### Install

```bash
dotnet add package CodeCargo.NatsDistributedCache
dotnet add package CodeCargo.NatsHybridCache
dotnet add package CodeCargo.Nats.DistributedCache
dotnet add package CodeCargo.Nats.HybridCacheExtensions
dotnet add package NATS.Net
```

### Example

```csharp
using CodeCargo.NatsHybridCache;
using CodeCargo.Nats.HybridCacheExtensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NATS.Client.Core;
Expand Down Expand Up @@ -85,14 +71,14 @@ await host.RunAsync();
### Install

```bash
dotnet add package CodeCargo.NatsDistributedCache
dotnet add package CodeCargo.Nats.DistributedCache
dotnet add package NATS.Net
```

### Example

```csharp
using CodeCargo.NatsDistributedCache;
using CodeCargo.Nats.DistributedCache;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NATS.Client.Core;
Expand Down
2 changes: 1 addition & 1 deletion src/NatsDistributedCache/NatsCache.Log.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;

namespace CodeCargo.NatsDistributedCache;
namespace CodeCargo.Nats.DistributedCache;

public partial class NatsCache
{
Expand Down
2 changes: 1 addition & 1 deletion src/NatsDistributedCache/NatsCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using NATS.Client.KeyValueStore;
using NATS.Net;

namespace CodeCargo.NatsDistributedCache;
namespace CodeCargo.Nats.DistributedCache;

/// <summary>
/// Cache entry for storing in NATS Key-Value Store
Expand Down
2 changes: 1 addition & 1 deletion src/NatsDistributedCache/NatsCacheOptions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Options;

namespace CodeCargo.NatsDistributedCache
namespace CodeCargo.Nats.DistributedCache
{
/// <summary>
/// Configuration options for <see cref="NatsCache"/>.
Expand Down
4 changes: 2 additions & 2 deletions src/NatsDistributedCache/NatsDistributedCache.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<RootNamespace>CodeCargo.NatsDistributedCache</RootNamespace>
<RootNamespace>CodeCargo.Nats.DistributedCache</RootNamespace>
<Description>NATS implementation of IDistributedCache.</Description>

<!-- Assembly signing (only if key file exists) -->
Expand All @@ -14,7 +14,7 @@
<Authors>CodeCargo</Authors>
<Company>CodeCargo</Company>
<Copyright>Copyright © $([System.DateTime]::Now.Year) CodeCargo</Copyright>
<PackageId>CodeCargo.NatsDistributedCache</PackageId>
<PackageId>CodeCargo.Nats.DistributedCache</PackageId>
<PackageTags>distributed cache;hybrid cache;nats</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
2 changes: 1 addition & 1 deletion src/NatsDistributedCache/NatsDistributedCacheExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using Microsoft.Extensions.Options;
using NATS.Client.Core;

namespace CodeCargo.NatsDistributedCache;
namespace CodeCargo.Nats.DistributedCache;

/// <summary>
/// Extension methods for setting up NATS distributed cache related services in an <see cref="IServiceCollection" />.
Expand Down
4 changes: 2 additions & 2 deletions src/NatsDistributedCache/NatsHybridCacheSerializer.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// even though this is an IHybridCacheSerializer, it's included in Microsoft.Extensions.Caching.Abstractions
// so we can include it in the NatsDistributedCache package instead of NatsHybridCache to give library
// so we can include it in the NatsDistributedCache package instead of NatsHybridCacheExtensions to give library
// consumers the option to reduce dependencies

using System.Buffers;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Caching.Hybrid;
using NATS.Client.Core;

namespace CodeCargo.NatsDistributedCache;
namespace CodeCargo.Nats.DistributedCache;

public readonly struct NatsHybridCacheSerializer<T>(INatsSerialize<T> serializer, INatsDeserialize<T> deserializer)
: IHybridCacheSerializer<T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CodeCargo.NatsDistributedCache;
using CodeCargo.Nats.DistributedCache;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.DependencyInjection;
using NATS.Client.Core;

namespace CodeCargo.NatsHybridCache;
namespace CodeCargo.Nats.HybridCacheExtensions;

/// <summary>
/// Extension methods for setting up NATS hybrid cache related services in an <see cref="IServiceCollection" />.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<IsPackable>true</IsPackable>
<Nullable>enable</Nullable>
<RootNamespace>CodeCargo.NatsHybridCache</RootNamespace>
<RootNamespace>CodeCargo.Nats.HybridCacheExtensions</RootNamespace>
<Description>Extensions for using HybridCache with NATS.</Description>

<!-- Assembly signing (only if key file exists) -->
Expand All @@ -14,7 +14,7 @@
<Authors>CodeCargo</Authors>
<Company>CodeCargo</Company>
<Copyright>Copyright © $([System.DateTime]::Now.Year) CodeCargo</Copyright>
<PackageId>CodeCargo.NatsHybridCache</PackageId>
<PackageId>CodeCargo.Nats.HybridCacheExtensions</PackageId>
<PackageTags>distributed cache;hybrid cache;nats</PackageTags>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"resolved": "8.0.5",
"contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg=="
},
"CodeCargo.NatsDistributedCache": {
"CodeCargo.Nats.DistributedCache": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "[9.0.4, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"resolved": "8.0.5",
"contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg=="
},
"CodeCargo.NatsDistributedCache": {
"CodeCargo.Nats.DistributedCache": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "[9.0.4, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
"resolved": "8.0.5",
"contentHash": "0f1B50Ss7rqxXiaBJyzUu9bWFOO2/zSlifZ/UNMdiIpDYe4cY4LQQicP4nirK1OS31I43rn062UIJ1Q9bpmHpg=="
},
"CodeCargo.NatsDistributedCache": {
"CodeCargo.Nats.DistributedCache": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "[9.0.4, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using NATS.Client.KeyValueStore;
using NATS.Net;

namespace CodeCargo.NatsDistributedCache.IntegrationTests.Cache;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests.Cache;

public class HybridCacheGetSetRemoveTests(NatsIntegrationFixture fixture) : TestBase(fixture)
{
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Cache/NatsCacheSetAndRemoveTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Text;
using Microsoft.Extensions.Caching.Distributed;

namespace CodeCargo.NatsDistributedCache.IntegrationTests.Cache;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests.Cache;

public class NatsCacheSetAndRemoveTests(NatsIntegrationFixture fixture) : TestBase(fixture)
{
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Cache/TimeExpirationAsyncTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Caching.Distributed;

namespace CodeCargo.NatsDistributedCache.IntegrationTests.Cache;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests.Cache;

public class TimeExpirationAsyncTests(NatsIntegrationFixture fixture) : TestBase(fixture)
{
Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/Cache/TimeExpirationTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Caching.Distributed;

namespace CodeCargo.NatsDistributedCache.IntegrationTests.Cache;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests.Cache;

public class TimeExpirationTests(NatsIntegrationFixture fixture) : TestBase(fixture)
{
Expand Down
4 changes: 2 additions & 2 deletions test/IntegrationTests/IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<IsTestProject>true</IsTestProject>
<RunSettingsFilePath>$(MSBuildProjectDirectory)\..\xunit.runsettings</RunSettingsFilePath>
<OutputType>Exe</OutputType>
<RootNamespace>CodeCargo.NatsDistributedCache.IntegrationTests</RootNamespace>
<RootNamespace>CodeCargo.Nats.DistributedCache.IntegrationTests</RootNamespace>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,7 +20,7 @@

<ItemGroup>
<ProjectReference Include="..\TestUtils\TestUtils.csproj" />
<ProjectReference Include="..\..\src\NatsHybridCache\NatsHybridCache.csproj" />
<ProjectReference Include="..\..\src\NatsHybridCacheExtensions\NatsHybridCacheExtensions.csproj" />
<ProjectReference Include="..\..\util\NatsAppHost\NatsAppHost.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion test/IntegrationTests/NatsCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CodeCargo.NatsDistributedCache.IntegrationTests;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests;

[CollectionDefinition(Name)]
public class NatsCollection : ICollectionFixture<NatsIntegrationFixture>
Expand Down
4 changes: 2 additions & 2 deletions test/IntegrationTests/NatsIntegrationFixture.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Aspire.Hosting;
using CodeCargo.NatsDistributedCache.TestUtils;
using CodeCargo.Nats.DistributedCache.TestUtils;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.KeyValueStore;
using NATS.Net;

namespace CodeCargo.NatsDistributedCache.IntegrationTests;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests;

/// <summary>
/// Test fixture that starts an Aspire-hosted NATS server for integration tests
Expand Down
6 changes: 3 additions & 3 deletions test/IntegrationTests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Runtime.CompilerServices;
using CodeCargo.NatsDistributedCache.TestUtils;
using CodeCargo.NatsDistributedCache.TestUtils.Services.Logging;
using CodeCargo.Nats.DistributedCache.TestUtils;
using CodeCargo.Nats.DistributedCache.TestUtils.Services.Logging;
using Microsoft.Extensions.Caching.Distributed;
using Microsoft.Extensions.Caching.Hybrid;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
using NATS.Client.JetStream.Models;
using NATS.Net;

namespace CodeCargo.NatsDistributedCache.IntegrationTests;
namespace CodeCargo.Nats.DistributedCache.IntegrationTests;

/// <summary>
/// Base class for NATS integration tests that provides test output logging and fixture access
Expand Down
10 changes: 5 additions & 5 deletions test/IntegrationTests/packages.linux-x64.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"CodeCargo.NatsDistributedCache": {
"CodeCargo.Nats.DistributedCache": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "[9.0.4, )",
Expand All @@ -1084,10 +1084,10 @@
"NATS.Client.KeyValueStore": "[2.6.0, )"
}
},
"CodeCargo.NatsHybridCache": {
"CodeCargo.Nats.HybridCacheExtensions": {
"type": "Project",
"dependencies": {
"CodeCargo.NatsDistributedCache": "[1.0.0, )",
"CodeCargo.Nats.DistributedCache": "[1.0.0, )",
"Microsoft.Extensions.Caching.Hybrid": "[9.4.0, )"
}
},
Expand All @@ -1097,13 +1097,13 @@
"Aspire.Dashboard.Sdk.linux-x64": "[9.2.1, )",
"Aspire.Hosting.AppHost": "[9.2.1, )",
"Aspire.Hosting.Orchestration.linux-x64": "[9.2.1, )",
"CodeCargo.NatsHybridCache": "[1.0.0, )"
"CodeCargo.Nats.HybridCacheExtensions": "[1.0.0, )"
}
},
"testutils": {
"type": "Project",
"dependencies": {
"CodeCargo.NatsHybridCache": "[1.0.0, )",
"CodeCargo.Nats.HybridCacheExtensions": "[1.0.0, )",
"Microsoft.Extensions.Logging": "[9.0.4, )",
"NATS.Net": "[2.6.0, )",
"xunit.v3.assert": "[2.0.2, )",
Expand Down
10 changes: 5 additions & 5 deletions test/IntegrationTests/packages.osx-arm64.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@
"resolved": "16.3.0",
"contentHash": "SgMOdxbz8X65z8hraIs6hOEdnkH6hESTAIUa7viEngHOYaH+6q5XJmwr1+yb9vJpNQ19hCQY69xbFsLtXpobQA=="
},
"CodeCargo.NatsDistributedCache": {
"CodeCargo.Nats.DistributedCache": {
"type": "Project",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "[9.0.4, )",
Expand All @@ -1084,10 +1084,10 @@
"NATS.Client.KeyValueStore": "[2.6.0, )"
}
},
"CodeCargo.NatsHybridCache": {
"CodeCargo.Nats.HybridCacheExtensions": {
"type": "Project",
"dependencies": {
"CodeCargo.NatsDistributedCache": "[1.0.0, )",
"CodeCargo.Nats.DistributedCache": "[1.0.0, )",
"Microsoft.Extensions.Caching.Hybrid": "[9.4.0, )"
}
},
Expand All @@ -1097,13 +1097,13 @@
"Aspire.Dashboard.Sdk.osx-arm64": "[9.2.1, )",
"Aspire.Hosting.AppHost": "[9.2.1, )",
"Aspire.Hosting.Orchestration.osx-arm64": "[9.2.1, )",
"CodeCargo.NatsHybridCache": "[1.0.0, )"
"CodeCargo.Nats.HybridCacheExtensions": "[1.0.0, )"
}
},
"testutils": {
"type": "Project",
"dependencies": {
"CodeCargo.NatsHybridCache": "[1.0.0, )",
"CodeCargo.Nats.HybridCacheExtensions": "[1.0.0, )",
"Microsoft.Extensions.Logging": "[9.0.4, )",
"NATS.Net": "[2.6.0, )",
"xunit.v3.assert": "[2.0.2, )",
Expand Down
Loading