Additions and extensions for .NET caching.
- Configuring caching through AppSettings.json
- Memory
- Redis (1) - you need to setup Redis, see below
- Redis (2) - || -
- Redis (3) - || -
- Redis (4) - || -
- Sqlite
- SqlServer (1)
- SqlServer (2)
Setup Redis locally with Docker:
docker run --rm -it -p 6379:6379 redis
- IDistributedCache-implementation with EntityFramework
May be used for development and test. May not be suted for production (regarding speed). But the database-context implementations can be used with a custom implementation of a database-driven cache built with sql-queries. That may speed it up. In that scenario the database-context is used for migrations. See the setup of SqlServerCache in this solution:
We might want to create/recreate migrations. If we can accept data-loss we can recreate the migrations otherwhise we will have to update them.
Copy all the commands below and run them in the Package Manager Console for the affected database-context.
If you want more migration-information you can add the -Verbose parameter:
Add-Migration TheMigration -Context TheDatabaseContext -OutputDir Data/Migrations -Project Project -StartupProject Application -Verbose;
Write-Host "Removing migrations...";
Remove-Migration -Context SqliteCacheContext -Force -Project Project -StartupProject Application;
Remove-Migration -Context SqlServerCacheContext -Force -Project Project -StartupProject Application;
Write-Host "Removing current migrations-directory...";
Remove-Item "Project\Distributed\Data\Migrations" -ErrorAction Ignore -Force -Recurse;
Write-Host "Creating migrations...";
Add-Migration SqliteCacheContextMigration -Context SqliteCacheContext -OutputDir Distributed/Data/Migrations/Sqlite -Project Project -StartupProject Application;
Add-Migration SqlServerCacheContextMigration -Context SqlServerCacheContext -OutputDir Distributed/Data/Migrations/SqlServer -Project Project -StartupProject Application;
Write-Host "Finnished";
Write-Host "Updating migrations...";
Add-Migration SqliteCacheContextMigrationUpdate -Context SqliteCacheContext -OutputDir Distributed/Data/Migrations/Sqlite -Project Project -StartupProject Application;
Add-Migration SqlServerCacheContextMigrationUpdate -Context SqlServerCacheContext -OutputDir Distributed/Data/Migrations/SqlServer -Project Project -StartupProject Application;
Write-Host "Finnished";