Skip to content

Commit dc12c44

Browse files
committed
Make GetOrCreateAsync example clearer
1 parent d1e5fd5 commit dc12c44

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

DigitalRuby.SimpleCache/DigitalRuby.SimpleCache.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
88
<IsPackable>true</IsPackable>
9-
<Version>1.0.6</Version>
9+
<Version>1.0.7</Version>
1010
<Title>Simple Cache</Title>
1111
<Authors>jjxtra</Authors>
1212
<Company>Digital Ruby, LLC</Company>
@@ -17,7 +17,7 @@
1717
<PackageReadmeFile>README.md</PackageReadmeFile>
1818
<RepositoryUrl>https://github.com/DigitalRuby/SimplePubSub</RepositoryUrl>
1919
<PackageTags>cache;simple;easy;ram;memory;file;disk;redis;distributed;idistributedcache;iconnectionmultiplexer;lock;distributedlock;stackexchange;stackoverflow;connectionmultiplexer;lazy;task;storm;lazycache;caching;invalidation;expiration;synchronization;powerful;layer;layers;layered;layeredcache</PackageTags>
20-
<PackageReleaseNotes>Add key to get or create async context, eliminate need to reference it in the lambda</PackageReleaseNotes>
20+
<PackageReleaseNotes>Make GetOrCreateAsync example in Readme.md more clear</PackageReleaseNotes>
2121
<AssemblyVersion></AssemblyVersion>
2222
<FileVersion></FileVersion>
2323
<PackageLicenseExpression>MIT</PackageLicenseExpression>

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ If you do know the approximate size of your object, you should specify the size
141141
```cs
142142
var result = await cache.GetOrCreateAsync<string>(key, duration, async context =>
143143
{
144-
// if your method returns a Task<T> here, you don't have to await if you are just forwarding a method call
145-
var value = await MyExpensiveFunctionThatReturnsAStringAsync();
146-
147144
// if you need the key, you can use context.Key to avoid capturing the key parameter, saving performance
145+
var value = await MyExpensiveFunctionThatReturnsAStringAsync();
148146

149147
// set the cache duration and size, this is an important step to not miss
150148
// the tuple is minutes, size
@@ -155,6 +153,8 @@ var result = await cache.GetOrCreateAsync<string>(key, duration, async context =
155153
context.Size = value.Length * 2;
156154

157155
// the context also has a CancelToken property if you need it
156+
157+
return value;
158158
}, stoppingToken);
159159
```
160160

0 commit comments

Comments
 (0)