Define a contract and many implementations (OnMemory, Azure Storage Blobs, Azure Redis) for caching
ERNI Academy StarterKit, PoC, or Gidelines. This is an about description of your repository.
This section should list any major frameworks that you built your project using. Leave any add-ons/plugins for the acknowledgements section. Here are a few examples.
Get GetAsync Set SetAsync Exists ExistsAsync Remove RemoveAsync
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
.net 6 Visual Studio or Visual Studio Code
Installation instructions Cache Abstraction by running:
- Clone the repo
git clone --recurse-submodules https://github.com/ERNI-Academy/assets-cache-abstraction.git
Important Note
All implementations heavly depends on Microsoft Options Pattern for configurations. See https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/options?view=aspnetcore-6.0 So it is expected a proper configuration in order to work take a look at the samples to see how to configure each All implementatins also depends on Microsoft logging. See https://docs.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line
- Cache Basic use
class MyItem
{
public string MyCustomProperty { get; set; }
}
var item = new MyItem { MyCustomProperty = "hi" };
//you can choose between many impl
ICacheManager cacheManager = new ErniAcademy.Cache.OnMemory.OnMemoryCacheManager();//args ommited for simplicity
ICacheManager cacheManager = new ErniAcademy.Cache.Redis.RedisCacheManager();//args ommited for simplicity
ICacheManager cacheManager = new ErniAcademy.Cache.StorageBlobs.StorageBlobsCacheManager();//args ommited for simplicity
//set an Item into cache
await cacheManager.SetAsync("key1", item);
//get an Item from cache
var cachedItem = await cacheManager.GetAsync<MyItem>("key1");
- Cache Depency injection (ServiceCollection)
class MyItem
{
public string MyCustomProperty { get; set; }
}
//when configuring your ServiceCollection use the extension methods defined in each library for easy of use.
//This sample is provided with no arguments, take a look on the extensions to see the rest of the arguments, like IConfiguration, ISerializer etc.
services.AddCacheOnMemory();//args ommited for simplicity
services.AddCacheRedis();//args ommited for simplicity
services.AddCacheStorageBlobs();//args ommited for simplicity
//then just inject ICacheManager directly in your classes
class MyService
{
private readonly ICacheManager _cacheManager;
public MyService(ICacheManager cacheManager)
{
_cacheManager = cacheManager;
}
public async Task SomeMethod()
{
//... some logic
var item = new MyItem { MyCustomProperty = "hi" };
//set an Item into cache
await _cacheManager.SetAsync("key1", item);
//get an Item from cache
var cachedItem = await _cacheManager.GetAsync<MyItem>("key1");
}
}
Please see our Contribution Guide to learn how to contribute.
(LICENSE) © 2022 ERNI - Swiss Software Engineering
Please see our Code of Conduct
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!