Sats.PostgresDistributedCache
1.2.0
dotnet add package Sats.PostgresDistributedCache --version 1.2.0
NuGet\Install-Package Sats.PostgresDistributedCache -Version 1.2.0
<PackageReference Include="Sats.PostgresDistributedCache" Version="1.2.0" />
paket add Sats.PostgresDistributedCache --version 1.2.0
#r "nuget: Sats.PostgresDistributedCache, 1.2.0"
// Install Sats.PostgresDistributedCache as a Cake Addin #addin nuget:?package=Sats.PostgresDistributedCache&version=1.2.0 // Install Sats.PostgresDistributedCache as a Cake Tool #tool nuget:?package=Sats.PostgresDistributedCache&version=1.2.0
Sats.PostgresDistributedCache
This is a custom distributed cache implementation using PostgreSQL as the backing store for caching. The cache supports basic caching operations like setting, getting, refreshing, and removing cache entries, along with support for expiration.
Installation
To install the Sats.PostgresDistributedCache
NuGet package, run the following command in your .NET project:
dotnet add package Sats.PostgresDistributedCache --version 1.2.0
Alternatively, you can use the NuGet Package Manager in Visual Studio.
Usage
- Configuration: In your
Startup.cs
orProgram.cs
(depending on your .NET version), configure the PostgreSQL distributed cache:
public void ConfigureServices(IServiceCollection services)
{
// Add PostgreSQL distributed cache with your connection string
services.AddPostgresDistributedCache(options =>
{
options.ConnectionString = "Host=myserver;Port=5432;Database=mydb;Username=myuser;Password=mypassword";
});
// Add other services as needed
}
- Using the Cache: You can inject
IPostgreSqlDistributedCache
into your services or controllers and use it as follows:
public class MyService
{
private readonly IPostgreSqlDistributedCache _distributedCache;
public MyService(IPostgreSqlDistributedCache distributedCache)
{
_distributedCache = distributedCache;
}
public async Task<string> GetFromCacheAsync(string key)
{
var data = await _distributedCache.GetAsync(key);
return data != null ? Encoding.UTF8.GetString(data) : null;
}
public async Task SetInCacheAsync(string key, string value)
{
var data = Encoding.UTF8.GetBytes(value);
await _distributedCache.SetAsync(key, data, expiration: TimeSpan.FromMinutes(10));
}
}
Table Schema
The cache is stored in a PostgreSQL table named Cache
with the following schema:
CREATE TABLE IF NOT EXISTS public."Cache"
(
"key" character varying(255) NOT NULL,
"value" text NOT NULL,
"expiration" timestamp with time zone,
CONSTRAINT "PK_Cache" PRIMARY KEY ("key"),
CONSTRAINT "UQ_Cache_Key" UNIQUE ("key")
);
Columns:
- Key: The key of the cache entry (mapped to
Key
in theCacheEntry
class). - Value: The value of the cache entry, stored as text (mapped to
Value
in theCacheEntry
class). - Expiration: The expiration time of the cache entry (mapped to
Expiration
in theCacheEntry
class).
Supported .NET Versions
This package supports the following .NET versions:
- .NET 6.0
- .NET 7.0
- .NET 8.0
- .NET 9.0
Make sure your project is targeting one of these versions to use Sats.PostgresDistributedCache
.
License
This package is licensed under the MIT License.
Links
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.1)
- Npgsql (>= 4.1.0)
-
net7.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.1)
- Npgsql (>= 4.1.0)
-
net8.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.1)
- Npgsql (>= 4.1.0)
-
net9.0
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.1)
- Microsoft.Extensions.DependencyInjection (>= 9.0.1)
- Npgsql (>= 4.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.0 | 27 | 1/28/2025 |