Thinkai.Utilities.Caching
1.0.0
dotnet add package Thinkai.Utilities.Caching --version 1.0.0
NuGet\Install-Package Thinkai.Utilities.Caching -Version 1.0.0
<PackageReference Include="Thinkai.Utilities.Caching" Version="1.0.0" />
paket add Thinkai.Utilities.Caching --version 1.0.0
#r "nuget: Thinkai.Utilities.Caching, 1.0.0"
// Install Thinkai.Utilities.Caching as a Cake Addin #addin nuget:?package=Thinkai.Utilities.Caching&version=1.0.0 // Install Thinkai.Utilities.Caching as a Cake Tool #tool nuget:?package=Thinkai.Utilities.Caching&version=1.0.0
Thinkai.Utilities.Caching
Thinkai.Utilities.Caching is a versatile and extensible caching library designed to provide seamless integration with mainstream caching solutions. It supports essential read and write functionalities and offers an extensible interface that allows users to implement their custom caching logic.
The library aims to simplify cache management while maintaining flexibility and extensibility for diverse application requirements.
Features
Out-of-the-box Support for Popular Caching Providers:
The library currently supports:- RedisCache
- InMemoryCache
- CosmosDbCache
- AwsDynamoDbCache
- GoogleCloudMemCache
Basic Read/Write Functionalities:
- Set a value in the cache with an optional expiration.
- Retrieve values from the cache.
- Remove a key from the cache.
- Check if a key exists in the cache.
- Clear all entries from the cache.
- Retrieve keys matching a pattern.
Extensible Design:
- Includes an extensible
ICachingServices
interface, allowing users to implement custom caching behavior. - Easily add private methods or extend functionality while leveraging the core capabilities.
- Includes an extensible
Factory Pattern Implementation:
- Dynamically switch between cache providers based on configuration.
Installation
- Clone or download the repository.
- Add the
Thinkai.Utilities.Caching
library as a reference to your project. - Install any necessary dependencies for the desired cache provider (e.g., Redis, CosmosDB SDK, AWS SDK, etc.).
Usage
1. Configure Your Application
Add the appropriate settings for the desired cache provider in your configuration file (e.g., appsettings.json
):
{
"CacheSettings": {
"Type": "Redis", // or MemCache, CosmosDb, AwsDynamoDb, GoogleCloudMem
"Redis": {
"RedisConnectionString": "localhost:6379",
"KeyValueTags": { "Tag1": "Value1" }
},
"InMemory": {
// In-memory cache-specific settings
},
"CosmosDb": {
"ConnectionString": "your-cosmosdb-connection-string"
},
"AwsDynamoDb": {
"ConnectionString": "your-dynamodb-connection-string"
},
"GoogleCloudMem": {
"ConnectionString": "your-google-cloud-memcached-connection-string"
}
}
}
2. Dependency Injection Setup
Register the caching services in your application’s Startup.cs
or Program.cs
file:
services.AddCacheLayer(Configuration);
3. Basic Caching Operations
Use CacheFactoryService
to interact with your configured cache:
public class TestCaching
{
private readonly CacheFactoryService _cacheService;
public TestCaching(CacheFactoryService cacheService)
{
_cacheService = cacheService;
}
public async Task RunCacheTests()
{
// Set a value
await _cacheService.Set("TestKey", "TestValue", TimeSpan.FromMinutes(10));
// Get a value
var value = await _cacheService.Get<string>("TestKey");
Console.WriteLine($"Retrieved Value: {value}");
// Check if a key exists
var exists = await _cacheService.CheckIfKeyExists("TestKey");
Console.WriteLine($"Key Exists: {exists}");
// Remove a key
await _cacheService.Remove("TestKey");
// Clear all cache entries
await _cacheService.ClearCache();
}
}
Extending the Library
You can add new caching implementations by extending the ICachingServices
interface:
public class CustomCache : ICachingServices
{
// Implement required methods such as Get, Set, Remove, etc.
}
Register the new cache in the factory:
switch (_allowedCache)
{
case AllowedCache.CustomCache:
return new CustomCache();
// Other cases
}
Contribution
Contributions to enhance the library or add support for additional cache providers are welcome!
Steps to Contribute
- Fork the repository.
- Create a new feature branch.
- Add and test your changes.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contact
For questions, issues, or feedback, feel free to reach out via the repository's issue tracker or contribute directly to the project.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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. |
-
net8.0
- Microsoft.Data.SqlClient (>= 5.2.2)
- Microsoft.Extensions.Options (>= 9.0.0)
- MySqlConnector (>= 2.3.7)
- Npgsql (>= 8.0.5)
- StackExchange.Redis (>= 2.8.16)
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.0.0 | 97 | 11/25/2024 |