This repo is a multi-targeted .NET library (C#), built with dotnet and tested with xUnit.
- Build solution (Release):
dotnet build -c Release FasterKv.Cache.sln
- Build a single project:
dotnet build -c Release src/FasterKv.Cache.Core/FasterKv.Cache.Core.csproj
- Run all tests (default frameworks in test project):
dotnet test tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj
- Run tests for a specific framework (CI uses net6.0..net10.0):
dotnet test --framework net8.0 tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj
xUnit runs via dotnet test using the VSTest filter syntax.
- Run a single test by fully-qualified name (recommended):
dotnet test tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj --filter "FullyQualifiedName=FasterKv.Cache.Core.Tests.Serializers.FasterKvSerializerSerializeTests.Expired_Value_Should_Only_Serialize_ExpiryTime"
- Run all tests in a class:
dotnet test tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj --filter "FullyQualifiedName~FasterKv.Cache.Core.Tests.Serializers.FasterKvSerializerSerializeTests"
- Run by method name substring:
dotnet test tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj --filter "Name~Serialize"
- Run by trait (only if tests define traits):
dotnet test ... --filter "Trait=Category=Slow"
Tip: add --framework net8.0 to any command when you want faster local iteration.
This repo does not currently define a dedicated linter/formatter command (no .editorconfig, dotnet format config, or stylecop config checked in).
If you want to format locally, use standard tooling (do not enforce via PR unless the repo adds it):
dotnet format FasterKv.Cache.sln(only if your environment hasdotnet-formatinstalled)
- Build:
dotnet build --configuration Release FasterKv.Cache.sln - Tests (Linux matrix):
dotnet test --framework=<net6.0|net7.0|net8.0|net9.0|net10.0> tests/FasterKv.Cache.Core.Tests/FasterKv.Cache.Core.Tests.csproj
This repo uses a "deny by default" pack strategy.
- Default:
IsPackable=falseviaDirectory.Build.props - Libraries: explicitly opt-in with
IsPackable=truein thesrc/project.csproj - Non-shipping projects (tests/benchmark/sample/tools): keep
IsPackable=false - Release workflows should push all produced
*.nupkgand rely onIsPackable(avoid filename-based skip lists)
- C# language version: 11 (
<LangVersion>11</LangVersion>) - Nullable reference types: enabled (
<Nullable>enable</Nullable>) - Warnings as errors: enabled (
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>) - Test assemblies get
InternalsVisibleTo $(AssemblyName).Tests
- Prefer file-scoped namespaces:
namespace FasterKv.Cache.Core.Tests.Serializers;
- One public type per file (exceptions: small internal helper types).
- Keep files small and focused; avoid "god" classes.
- Keep
usingdirectives at the top; avoid mid-fileusing. - Sort usings:
System.*first, then third-party, then project namespaces. - Prefer
global usingfor ubiquitous test-only imports (already used:global using Xunit;intests/FasterKv.Cache.Core.Tests/Usings.cs). - Avoid unused usings; treat warnings as errors will break the build.
- Namespaces:
FasterKv.Cache.<Area>. - Types/methods/properties:
PascalCase. - Local variables/parameters:
camelCase. - Private fields:
_camelCase. - Interfaces:
IThing. - Async methods: suffix
Async. - Tests:
- Keep descriptive names; existing tests often use underscores for readability.
- Keep nullability correct; prefer non-nullable by default.
- Use
ArgumentNullException.ThrowIfNull(x)for required parameters. - Use
varwhen the RHS makes the type obvious; otherwise use explicit types. - Prefer
readonlyfor fields and locals when possible.
- Follow standard C# conventions:
- 4-space indentation.
- Braces on the next line for types/members.
- Keep line length reasonable; wrap fluent chains.
- Prefer expression-bodied members only when it improves readability.
- Do not swallow exceptions silently.
- Throw framework exceptions for argument validation:
ArgumentException,ArgumentOutOfRangeException,InvalidOperationException.
- When surfacing errors from the underlying FASTER engine, include enough context (cache name, key info, operation) but avoid logging/throwing sensitive payloads.
- Prefer "Try" APIs (
TryGet...,TryRecover...) when failure is a normal outcome.
This library targets high performance.
- Avoid unnecessary allocations on hot paths:
- Prefer spans/
ReadOnlySpan<T>/ pooled buffers where appropriate. - Minimize boxing (especially for the non-generic cache API).
- Prefer spans/
- Dispose resources deterministically:
- Use
using var ...;forStream,IDisposableobjects.
- Use
- Be careful with async/await overhead in tight loops.
- Use
[Fact]for single-case tests;[Theory]+[InlineData]for parameterized tests. - Prefer behavior-focused tests with clear Arrange/Act/Assert separation.
- When mocking:
- Keep setups minimal.
- Verify important interactions; avoid over-specification.
- Cursor rules: none found (no
.cursor/rules/and no.cursorrules). - Copilot instructions: none found (no
.github/copilot-instructions.md).
- Multi-targeting: ensure changes compile across
net6.0,net7.0,net8.0,net9.0,net10.0(andnetstandard2.0for core library). - Warnings are errors: even minor warnings will fail CI.
- When adding packages, consider framework-specific references (see existing per-TFM package references).