Skip to content

Commit

Permalink
Updated example to include DI usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Turnerj committed Nov 3, 2019
1 parent 5ccd7b8 commit a67a1d2
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<SomeClassThatExtendsICacheContext>(
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<SomeClassThatExtendsICacheContext>(myContext, new [] {
new MemoryCacheLayer(),
new ProtobufFileCacheLayer("directory/where/the/cache/can/write")
}, new [] {
Expand All @@ -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<MyTypeInTheCache>("MyCacheKey", async (old, context) => {
Expand Down

0 comments on commit a67a1d2

Please sign in to comment.