Skip to content

Commit 8ea6bbe

Browse files
committed
[memoryCache] fixed GetValue returns empty (issue exilon#73)
1 parent ee974f3 commit 8ea6bbe

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

Quick.MemoryCache.pas

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{ ***************************************************************************
22
3-
Copyright (c) 2016-2019 Kike Pérez
3+
Copyright (c) 2016-2021 Kike Pérez
44
55
Unit : Quick.MemoryCache
66
Description : Cache objects with expiration control
77
Author : Kike Pérez
88
Version : 1.0
99
Created : 14/07/2019
10-
Modified : 02/11/2019
10+
Modified : 17/05/2021
1111
1212
This file is part of QuickLib: https://github.com/exilon/QuickLib
1313
@@ -479,15 +479,8 @@ constructor TMemoryCache<T>.Create(aPurgerInterval: Integer; aCacheSerializer: I
479479
end;
480480

481481
function TMemoryCache<T>.GetValue(const aKey: string): T;
482-
var
483-
cacheitem : ICacheEntry;
484482
begin
485-
fLock.BeginRead;
486-
try
487-
fItems.TryGetValue(aKey,cacheitem);
488-
finally
489-
fLock.EndRead;
490-
end;
483+
TryGetValue(aKey,Result);
491484
end;
492485

493486
procedure TMemoryCache<T>.RemoveValue(const aKey: string);
@@ -595,10 +588,8 @@ function TMemoryCache<T>.TryGetValue(const aKey: string; out oValue: T): Boolean
595588
{ TMemoryCache }
596589

597590
function TMemoryCache.GetValue(const aKey: string): string;
598-
var
599-
cacheitem : ICacheEntry;
600591
begin
601-
if fItems.TryGetValue(aKey,cacheitem) then Result := cacheitem.Data;
592+
TryGetValue(aKey,Result);
602593
end;
603594

604595
procedure TMemoryCache.SetValue(const aKey, aValue: string; aExpirationMilliseconds: Integer);
@@ -701,7 +692,7 @@ function TMemoryCache.TryGetValue<T>(const aKey: string; out oValue: T): Boolean
701692
try
702693
Result := fItems.TryGetValue(aKey,cacheitem);
703694
//check if cacheitem already expired
704-
if Result and cacheitem.IsExpired then Exit(False);
695+
if Result and cacheitem.IsExpired then Exit(False);
705696
finally
706697
fLock.EndRead;
707698
end;

0 commit comments

Comments
 (0)