From a67a1d2e195c13a28142d2cd7c8944520f86e043 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Sun, 3 Nov 2019 15:24:04 +1030 Subject: [PATCH] Updated example to include DI usage --- README.md | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d27b22c5..b6489a9c 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,32 @@ While this can work independently of using `RedisLockExtension` or even the `Red ## Example Usage -Setup and store a singleton of `CacheStack` (whether that is via Dependency Injection or a static variable). +### Setup with DI +```csharp + +public void ConfigureServices(IServiceCollection services) +{ + services.AddCacheStack( + new [] { + new MemoryCacheLayer(), + new ProtobufFileCacheLayer("directory/where/the/cache/can/write") + }, + new [] { + new AutoCleanupExtension(TimeSpan.FromMinutes(5)) + } + ); +} + +``` + +### Setup without DI +Setup and store a singleton of `CacheStack` ```csharp //Context is allowed to be null if you don't need it var myContext = new SomeClassThatExtendsICacheContext(); -var myCacheStack = new CacheStack(myContext, new [] { +var myCacheStack = new CacheStack(myContext, new [] { new MemoryCacheLayer(), new ProtobufFileCacheLayer("directory/where/the/cache/can/write") }, new [] { @@ -93,6 +112,8 @@ var myCacheStack = new CacheStack(myContext, new [] { ``` +### Accessing the Cache + Somewhere in your code base where you are wanting to optionally pull data from your cache. ```csharp await myCacheStack.GetOrSetAsync("MyCacheKey", async (old, context) => {