Sats.PostgresDistributedCache 1.2.0

dotnet add package Sats.PostgresDistributedCache --version 1.2.0                
NuGet\Install-Package Sats.PostgresDistributedCache -Version 1.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sats.PostgresDistributedCache" Version="1.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sats.PostgresDistributedCache --version 1.2.0                
#r "nuget: Sats.PostgresDistributedCache, 1.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// 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.

NuGet Badge

Usage

  1. Configuration: In your Startup.cs or Program.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
}
  1. 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 the CacheEntry class).
  • Value: The value of the cache entry, stored as text (mapped to Value in the CacheEntry class).
  • Expiration: The expiration time of the cache entry (mapped to Expiration in the CacheEntry 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.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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