Skip to content

A PostgreSQL Implementation of IDistributedCache interface. Using Postgresql as distributed cache in Asp.Net Core. NetStandard 2.0

Notifications You must be signed in to change notification settings

griffo-io/community-extensions-cache-postgres

 
 

Repository files navigation

Community.Microsoft.Extensions.Caching.PostgreSQL

Description

This implemantation uses PostgreSQL as distributed cache.

Getting Started

  1. Install the package into your project
dotnet add package Community.Microsoft.Extensions.Caching.PostgreSql
  1. Add the following line to the Startup Configure method.
services.AddDistributedPostgreSqlCache(setup => 
{
	ConnectionString = configuration["ConnectionString"], 
	SchemaName = configuration["SchemaName"],
	TableName = configuration["TableName"],
	CreateInfrastructure = configuration["CreateInfrastructure"] 
	// CreateInfrastructure is optional, default is TRUE
	// This means que every time starts the application the 
	// creation of table and database functions will be verified.
})
  1. Then pull from DI like any other service
    private readonly IDistributedCache _cache;

    public WeatherForecastController(IDistributedCache cache)
    {
        _cache = cache;
    }

What it does to my database:

Creates a table and six functions, see scripts folder for more details.

[schemaName].datediff
[schemaName].deletecacheitemformat
[schemaName].deleteexpiredcacheitemsformat
[schemaName].getcacheitemformat
[schemaName].setcache
[schemaName].updatecacheitemformat

Runing the console sample

You will need a local postgresql server with this configuration:

  1. Server listening to port 5432 at localhost
  2. The password of your postgres account, if not attached already to your user.
  3. Clone this repo.
  4. Run the following commands inside PostgreSqlCacheSample:
dotnet restore
prepare-database.cmd -create
dotnet run

S

Then you can delete the database with:

prepare-database.cmd -erase

Change Log

  1. v3.0
    1. [BREAKING CHANGE] - Direct instantiation not preferred
    2. Single thread loop remover
  2. v2.0.x - Update everything to net5.0, more detailed sample project.
  3. v1.0.8 - Update to latest dependencies -

License

  • MIT

This is a fork from repo

About

A PostgreSQL Implementation of IDistributedCache interface. Using Postgresql as distributed cache in Asp.Net Core. NetStandard 2.0

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 70.0%
  • JavaScript 16.2%
  • PLpgSQL 9.2%
  • HTML 3.3%
  • CSS 0.8%
  • Batchfile 0.5%