|
1 | 1 | { ***************************************************************************
|
2 | 2 |
|
3 |
| - Copyright (c) 2016-2019 Kike Pérez |
| 3 | + Copyright (c) 2016-2021 Kike Pérez |
4 | 4 |
|
5 | 5 | Unit : Quick.MemoryCache
|
6 | 6 | Description : Cache objects with expiration control
|
7 | 7 | Author : Kike Pérez
|
8 | 8 | Version : 1.0
|
9 | 9 | Created : 14/07/2019
|
10 |
| - Modified : 02/11/2019 |
| 10 | + Modified : 17/05/2021 |
11 | 11 |
|
12 | 12 | This file is part of QuickLib: https://github.com/exilon/QuickLib
|
13 | 13 |
|
@@ -479,15 +479,8 @@ constructor TMemoryCache<T>.Create(aPurgerInterval: Integer; aCacheSerializer: I
|
479 | 479 | end;
|
480 | 480 |
|
481 | 481 | function TMemoryCache<T>.GetValue(const aKey: string): T;
|
482 |
| -var |
483 |
| - cacheitem : ICacheEntry; |
484 | 482 | begin
|
485 |
| - fLock.BeginRead; |
486 |
| - try |
487 |
| - fItems.TryGetValue(aKey,cacheitem); |
488 |
| - finally |
489 |
| - fLock.EndRead; |
490 |
| - end; |
| 483 | + TryGetValue(aKey,Result); |
491 | 484 | end;
|
492 | 485 |
|
493 | 486 | procedure TMemoryCache<T>.RemoveValue(const aKey: string);
|
@@ -595,10 +588,8 @@ function TMemoryCache<T>.TryGetValue(const aKey: string; out oValue: T): Boolean
|
595 | 588 | { TMemoryCache }
|
596 | 589 |
|
597 | 590 | function TMemoryCache.GetValue(const aKey: string): string;
|
598 |
| -var |
599 |
| - cacheitem : ICacheEntry; |
600 | 591 | begin
|
601 |
| - if fItems.TryGetValue(aKey,cacheitem) then Result := cacheitem.Data; |
| 592 | + TryGetValue(aKey,Result); |
602 | 593 | end;
|
603 | 594 |
|
604 | 595 | procedure TMemoryCache.SetValue(const aKey, aValue: string; aExpirationMilliseconds: Integer);
|
@@ -701,7 +692,7 @@ function TMemoryCache.TryGetValue<T>(const aKey: string; out oValue: T): Boolean
|
701 | 692 | try
|
702 | 693 | Result := fItems.TryGetValue(aKey,cacheitem);
|
703 | 694 | //check if cacheitem already expired
|
704 |
| - if Result and cacheitem.IsExpired then Exit(False); |
| 695 | + if Result and cacheitem.IsExpired then Exit(False); |
705 | 696 | finally
|
706 | 697 | fLock.EndRead;
|
707 | 698 | end;
|
|
0 commit comments