@@ -19,15 +19,9 @@ public class MemoryCache : IMemoryCache
1919 private readonly TimeSpan expirationScanFrequency ;
2020 private DateTimeOffset lastExpirationScan ;
2121
22- public int Count
23- {
24- get { return this . entries . Count ; }
25- }
22+ public int Count => this . entries . Count ;
2623
27- private ICollection < KeyValuePair < object , CacheEntry > > EntriesCollection
28- {
29- get { return this . entries ; }
30- }
24+ private ICollection < KeyValuePair < object , CacheEntry > > EntriesCollection => this . entries ;
3125
3226 public MemoryCache ( ) : this ( new MemoryCacheOptions ( ) )
3327 {
@@ -66,12 +60,12 @@ private void SetEntry(CacheEntry entry)
6660 return ;
6761 }
6862
69- DateTimeOffset utcNow = this . clock . UtcNow ;
70- DateTimeOffset ? nullable = new DateTimeOffset ? ( ) ;
63+ var utcNow = this . clock . UtcNow ;
64+ var nullable = new DateTimeOffset ? ( ) ;
7165 if ( entry . absoluteExpirationRelativeToNow . HasValue )
7266 {
73- DateTimeOffset dateTimeOffset = utcNow ;
74- TimeSpan ? expirationRelativeToNow = entry . absoluteExpirationRelativeToNow ;
67+ var dateTimeOffset = utcNow ;
68+ var expirationRelativeToNow = entry . absoluteExpirationRelativeToNow ;
7569 nullable = expirationRelativeToNow . HasValue ? dateTimeOffset + expirationRelativeToNow . GetValueOrDefault ( ) : new DateTimeOffset ? ( ) ;
7670 }
7771 else if ( entry . absoluteExpiration . HasValue )
@@ -142,10 +136,9 @@ public bool TryGetValue(object key, out object result)
142136
143137 this . CheckDisposed ( ) ;
144138 result = null ;
145- DateTimeOffset utcNow = this . clock . UtcNow ;
146- bool flag = false ;
147- CacheEntry entry ;
148- if ( this . entries . TryGetValue ( key , out entry ) )
139+ var utcNow = this . clock . UtcNow ;
140+ var flag = false ;
141+ if ( this . entries . TryGetValue ( key , out var entry ) )
149142 {
150143 if ( entry . CheckExpired ( utcNow ) && entry . EvictionReason != EvictionReason . Replaced )
151144 {
@@ -172,8 +165,7 @@ public void Remove(object key)
172165 }
173166
174167 this . CheckDisposed ( ) ;
175- CacheEntry cacheEntry ;
176- if ( this . entries . TryRemove ( key , out cacheEntry ) )
168+ if ( this . entries . TryRemove ( key , out var cacheEntry ) )
177169 {
178170 cacheEntry . SetExpired ( EvictionReason . Removed ) ;
179171 cacheEntry . InvokeEvictionCallbacks ( ) ;
@@ -216,22 +208,22 @@ private void EntryExpired(CacheEntry entry)
216208
217209 private void StartScanForExpiredItems ( )
218210 {
219- DateTimeOffset utcNow = this . clock . UtcNow ;
211+ var utcNow = this . clock . UtcNow ;
220212 if ( ! ( this . expirationScanFrequency < utcNow - this . lastExpirationScan ) )
221213 {
222214 return ;
223215 }
224216
225217 this . lastExpirationScan = utcNow ;
226- TaskFactory factory = Task . Factory ;
227- CancellationToken none = CancellationToken . None ;
228- TaskScheduler scheduler = TaskScheduler . Default ;
218+ var factory = Task . Factory ;
219+ var none = CancellationToken . None ;
220+ var scheduler = TaskScheduler . Default ;
229221 factory . StartNew ( state => ScanForExpiredItems ( ( MemoryCache ) state ) , this , none , TaskCreationOptions . DenyChildAttach , scheduler ) ;
230222 }
231223
232224 private static void ScanForExpiredItems ( MemoryCache cache )
233225 {
234- DateTimeOffset utcNow = cache . clock . UtcNow ;
226+ var utcNow = cache . clock . UtcNow ;
235227 foreach ( var entry in cache . entries . Values )
236228 {
237229 if ( entry . CheckExpired ( utcNow ) )
@@ -243,13 +235,13 @@ private static void ScanForExpiredItems(MemoryCache cache)
243235
244236 public void Compact ( double percentage )
245237 {
246- List < CacheEntry > entriesToRemove = new List < CacheEntry > ( ) ;
247- List < CacheEntry > priorityEntries1 = new List < CacheEntry > ( ) ;
248- List < CacheEntry > priorityEntries2 = new List < CacheEntry > ( ) ;
249- List < CacheEntry > priorityEntries3 = new List < CacheEntry > ( ) ;
250- DateTimeOffset utcNow = this . clock . UtcNow ;
238+ var entriesToRemove = new List < CacheEntry > ( ) ;
239+ var priorityEntries1 = new List < CacheEntry > ( ) ;
240+ var priorityEntries2 = new List < CacheEntry > ( ) ;
241+ var priorityEntries3 = new List < CacheEntry > ( ) ;
242+ var utcNow = this . clock . UtcNow ;
251243
252- foreach ( CacheEntry cacheEntry in this . entries . Values )
244+ foreach ( var cacheEntry in this . entries . Values )
253245 {
254246 if ( cacheEntry . CheckExpired ( utcNow ) )
255247 {
@@ -271,12 +263,12 @@ public void Compact(double percentage)
271263 case 3 :
272264 continue ;
273265 default :
274- throw new NotSupportedException ( "Not implemented: " + ( object ) cacheEntry . Priority ) ;
266+ throw new NotSupportedException ( "Not implemented: " + cacheEntry . Priority ) ;
275267 }
276268 }
277269 }
278270
279- int removalCountTarget = ( int ) ( this . entries . Count * percentage ) ;
271+ var removalCountTarget = ( int ) ( this . entries . Count * percentage ) ;
280272 this . ExpirePriorityBucket ( removalCountTarget , entriesToRemove , priorityEntries1 ) ;
281273 this . ExpirePriorityBucket ( removalCountTarget , entriesToRemove , priorityEntries2 ) ;
282274 this . ExpirePriorityBucket ( removalCountTarget , entriesToRemove , priorityEntries3 ) ;
0 commit comments