You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With in-memory caching services registered, and resolved through DI — you're ready to start caching. This sample iterates through the letters in the English alphabet 'A' through 'Z'. There is a `record` that holds the reference to the letter, and generates a message.
58
+
With in-memory caching services registered, and resolved through DI — you're ready to start caching. This sample iterates through the letters in the English alphabet 'A' through 'Z'. The `record AlphabetLetter` type holds the reference to the letter, and generates a message.
- The invocation of `IterateAlphabetAsync` is awaited.
77
+
- The variable `addLettersToCacheTask` delegates to `IterateAlphabetAsync` and is awaited.
78
78
- The `Func<char, Task> asyncFunc` is argued with a lambda.
79
79
- The `MemoryCacheEntryOptions` is instantiated with an absolute expiration relative to now.
80
80
- A post eviction callback is registered.
@@ -90,7 +90,7 @@ The post eviction callback writes the details of the value that was evicted to t
90
90
91
91
Now that the cache is populated, another call to `IterateAlphabetAsync` is awaited, but this time you'll call <xref:Microsoft.Extensions.Caching.Memory.IMemoryCache.TryGetValue%2A?displayProperty=nameWithType>:
If the `cache` contains the `letter` key, and the `value` is an instance of an `AlphabetLetter` it's written to the console. When the `letter` key is not in the cache, it was evicted and its post eviction callback was invoked.
96
96
@@ -143,29 +143,29 @@ X was cached.
143
143
Y was cached.
144
144
Z was cached.
145
145
146
-
Q is still in cache. The 'Q' character is the 17 letter in the English alphabet.
147
-
R is still in cache. The 'R' character is the 18 letter in the English alphabet.
148
-
S is still in cache. The 'S' character is the 19 letter in the English alphabet.
149
-
T is still in cache. The 'T' character is the 20 letter in the English alphabet.
150
-
U is still in cache. The 'U' character is the 21 letter in the English alphabet.
151
-
D was evicted for Expired.
146
+
A was evicted for Expired.
152
147
C was evicted for Expired.
153
-
G was evicted for Expired.
148
+
B was evicted for Expired.
154
149
E was evicted for Expired.
150
+
D was evicted for Expired.
155
151
F was evicted for Expired.
156
-
B was evicted for Expired.
157
-
M was evicted for Expired.
158
-
V is still in cache. The 'V' character is the 22 letter in the English alphabet.
159
152
H was evicted for Expired.
160
-
I was evicted for Expired.
161
-
J was evicted for Expired.
162
153
K was evicted for Expired.
163
154
L was evicted for Expired.
164
-
A was evicted for Expired.
155
+
J was evicted for Expired.
156
+
G was evicted for Expired.
157
+
M was evicted for Expired.
165
158
N was evicted for Expired.
166
-
W is still in cache. The 'W' character is the 23 letter in the English alphabet.
167
-
O was evicted for Expired.
159
+
I was evicted for Expired.
168
160
P was evicted for Expired.
161
+
R was evicted for Expired.
162
+
O was evicted for Expired.
163
+
Q was evicted for Expired.
164
+
S is still in cache. The 'S' character is the 19 letter in the English alphabet.
165
+
T is still in cache. The 'T' character is the 20 letter in the English alphabet.
166
+
U is still in cache. The 'U' character is the 21 letter in the English alphabet.
167
+
V is still in cache. The 'V' character is the 22 letter in the English alphabet.
168
+
W is still in cache. The 'W' character is the 23 letter in the English alphabet.
169
169
X is still in cache. The 'X' character is the 24 letter in the English alphabet.
170
170
Y is still in cache. The 'Y' character is the 25 letter in the English alphabet.
171
171
Z is still in cache. The 'Z' character is the 26 letter in the English alphabet.
0 commit comments