PersistedCache 0.0.1
See the version list below for details.
dotnet add package PersistedCache --version 0.0.1
NuGet\Install-Package PersistedCache -Version 0.0.1
<PackageReference Include="PersistedCache" Version="0.0.1" />
paket add PersistedCache --version 0.0.1
#r "nuget: PersistedCache, 0.0.1"
// Install PersistedCache as a Cake Addin #addin nuget:?package=PersistedCache&version=0.0.1 // Install PersistedCache as a Cake Tool #tool nuget:?package=PersistedCache&version=0.0.1
Persisted Cache
Persisted Cache is a simple caching library that allows you to turn any stateful resource into a key-value store. It is designed to be simple and easy to use, meanwhile it spare you the hassle and costs of managing a separate cache server.
Why would you use this?
- Your team doesn't want to manage a separate cache server.
- You need a distributed cache that can be shared across multiple instances of your application.
- You need a cache that can be persisted to disk.
- You need a cache that can be shared across multiple applications.
How to use it?
Install the specific package for the resource you want to use. For example, if you want to use MySQL as the cache store, you would install the PersistedCache.MySql
package.
dotnet add package PersistedCache.MySql
Or simply add it from the NuGet package gallery.
Currently supported and planned resources are:
-
MySQL
- PersistedCache.MySql -
PostgreSQL
-
SQLite
-
MongoDB
-
SQL Server
-
File System
-
AWS S3
(maybe) -
Azure Blob Storage
(maybe)
Add the service to your DI container
services.AddMySqlPersistedCache("Your connection string here", options =>
{
// The name of the table to use for the cache
options.TableName = "persisted_cache";
// Can be set to false after the table is created (or if you want to manage the table yourself)
options.CreateTableIfNotExists = true;
// Purges expired entries based on configured expiry interval
options.PurgeExpiredEntries = true;
// The interval at which the cache purges expired entries
options.PurgeInterval = TimeSpan.FromHours(24);
// If you need to serialize/deserialize objects differently
options.JsonOptions = new JsonSerializerOptions()
});
All the options shown above are optional and have default values, only the connection string is required.
Use the cache
public class MyService
{
private readonly IPersistedCache _cache;
public MyService(IPersistedCache cache)
{
_cache = cache;
}
public void SetSomething()
{
_cache.Set("my-key", "some value", Expire.InMinutes(5));
}
public string GetSomething()
{
return _cache.Get<string>("my-key");
}
}
Methods
Method | Description |
---|---|
Set<T>(string key, T value, Expire expiry) |
Set a value in the cache with an expiry time |
SetForever<T>(string key, T value) |
Set a value in the cache forever |
SetAsync<T>(string key, T value, Expire expiry, CancellationToken cancellationToken = default) |
Set a value in the cache with an expiry time asynchronously |
SetForeverAsync<T>(string key, T value, CancellationToken cancellationToken = default) |
Set a value in the cache forever asynchronously |
Get<T>(string key) |
Get a value from the cache |
GetAsync<T>(string key, CancellationToken cancellationToken = default) |
Get a value from the cache asynchronously |
GetOrSet<T>(string key, Func<T> valueFactory, Expire expiry) |
Get a value from the cache or set it if it doesn't exist |
GetOrSetForever<T>(string key, Func<T> valueFactory) |
Get a value from the cache or set it if it doesn't exist forever |
GetOrSetAsync<T>(string key, Func<Task<T>> valueFactory, Expire expiry, CancellationToken cancellationToken = default) |
Get a value from the cache or set it if it doesn't exist asynchronously |
GetOrSetForeverAsync<T>(string key, Func<Task<T>> valueFactory, CancellationToken cancellationToken = default) |
Get a value from the cache or set it if it doesn't exist forever asynchronously |
Forget(string key) |
Forget a value from the cache |
ForgetAsync(string key, CancellationToken cancellationToken = default) |
Forget a value from the cache asynchronously |
Pull<T>(string key) |
Get a value from the cache and remove it |
PullAsync<T>(string key, CancellationToken cancellationToken = default) |
Get a value from the cache and remove it asynchronously |
Flush() |
Flush all values from the cache |
FlushAsync(CancellationToken cancellationToken = default) |
Flush all values from the cache asynchronously |
Flush(string pattern) |
Flush values from the cache by pattern |
FlushAsync(string pattern, CancellationToken cancellationToken = default) |
Flush values from the cache by pattern asynchronously |
Purge() |
Purge the cache of expired entries |
Want to contribute?
If you want to contribute to this project, please feel free to open an issue or a pull request.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Dapper (>= 2.1.35)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- System.Text.Json (>= 6.0.9)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on PersistedCache:
Package | Downloads |
---|---|
PersistedCache.MySql
Simple persisted cache for .NET and MySQL |
|
PersistedCache.PostgreSql
Simple persisted cache for .NET and PostgreSQL |
|
PersistedCache.SqlServer
Simple persisted cache for .NET and Microsoft Sql Server |
|
PersistedCache.FileSystem
Simple persisted cache for .NET and file system |
|
PersistedCache.Sqlite
Simple persisted cache for .NET and SQLite |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.1.0 | 233 | 9/21/2024 |
2.0.0 | 277 | 9/21/2024 |
1.0.3 | 250 | 9/21/2024 |
1.0.2 | 294 | 9/2/2024 |
1.0.1 | 129 | 8/21/2024 |
1.0.0 | 135 | 8/21/2024 |
0.1.1 | 130 | 8/21/2024 |
0.1.0 | 125 | 8/21/2024 |
0.0.13 | 129 | 8/21/2024 |
0.0.12 | 123 | 8/20/2024 |
0.0.11 | 306 | 8/19/2024 |
0.0.10 | 280 | 8/18/2024 |
0.0.9 | 138 | 8/18/2024 |
0.0.8 | 113 | 8/18/2024 |
0.0.7 | 110 | 8/18/2024 |
0.0.6 | 133 | 8/18/2024 |
0.0.5 | 135 | 8/18/2024 |
0.0.4 | 260 | 8/15/2024 |
0.0.3 | 227 | 8/15/2024 |
0.0.2 | 122 | 8/15/2024 |
0.0.1 | 177 | 8/15/2024 |