Browse Source

Minor improvement on TAbstractMemList adding "UseCacheAuto" property (Default True)

Pascal Coin 4 years ago
parent
commit
7c6e264c91

+ 1 - 1
src/core/UPCAbstractMem.pas

@@ -591,7 +591,7 @@ var
 begin
 begin
   FStats.Clear;
   FStats.Clear;
 
 
-  FUseCacheOnAbstractMemLists := True;
+  FUseCacheOnAbstractMemLists := False;
   FMaxMemUsage := 100 * 1024 * 1024;
   FMaxMemUsage := 100 * 1024 * 1024;
 
 
   FBlocks := Nil;
   FBlocks := Nil;

+ 1 - 1
src/core/upcdaemon.pas

@@ -266,7 +266,7 @@ begin
       FNode := TNode.Node;
       FNode := TNode.Node;
       {$IFDEF USE_ABSTRACTMEM}
       {$IFDEF USE_ABSTRACTMEM}
       LMaxMemMb := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_MAX_CACHE_MB,100);
       LMaxMemMb := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_MAX_CACHE_MB,100);
-      LUseCacheOnMemLists:= FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_USE_CACHE_ON_LISTS,False);
+      LUseCacheOnMemLists:= FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_USE_CACHE_ON_LISTS,True);
       LCacheMaxAccounts := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_ACCOUNTS,10000);
       LCacheMaxAccounts := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_ACCOUNTS,10000);
       LCacheMaxPubKeys := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_PUBKEYS,5000);
       LCacheMaxPubKeys := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_ABSTRACTMEM_CACHE_MAX_PUBKEYS,5000);
 
 

+ 12 - 8
src/libraries/abstractmem/UAbstractMemTList.pas

@@ -57,6 +57,7 @@ type
     FNextElementPosition : Integer;
     FNextElementPosition : Integer;
 
 
     FUseCache : Boolean;
     FUseCache : Boolean;
+    FUseCacheAuto : Boolean;
     FCacheData : TBytes;
     FCacheData : TBytes;
     FCacheUpdated : Boolean;
     FCacheUpdated : Boolean;
     FCacheDataLoaded : Boolean;
     FCacheDataLoaded : Boolean;
@@ -65,7 +66,7 @@ type
     function GetPosition(AIndex: Integer): TAbstractMemPosition;
     function GetPosition(AIndex: Integer): TAbstractMemPosition;
     procedure SetPosition(AIndex: Integer; const Value: TAbstractMemPosition);
     procedure SetPosition(AIndex: Integer; const Value: TAbstractMemPosition);
 
 
-    function UseCacheData : Boolean;
+    function UseCacheData(AWillUpdateData : Boolean) : Boolean;
     Procedure CheckInitialized;
     Procedure CheckInitialized;
     procedure GetPointerTo(AIndex : Integer; AAllowIncrease : Boolean; out APreviousBlockPointer, ABlockPointer : TAbstractMemPosition; out AIndexInBlock : Integer);
     procedure GetPointerTo(AIndex : Integer; AAllowIncrease : Boolean; out APreviousBlockPointer, ABlockPointer : TAbstractMemPosition; out AIndexInBlock : Integer);
     procedure AddRange(AIndexStart, AInsertCount : Integer);
     procedure AddRange(AIndexStart, AInsertCount : Integer);
@@ -95,6 +96,7 @@ type
     property AbstractMem : TAbstractMem read FAbstractMem;
     property AbstractMem : TAbstractMem read FAbstractMem;
     property InitialiZone : TAMZone read FInitialZone;
     property InitialiZone : TAMZone read FInitialZone;
     property UseCache : Boolean read FUseCache write SetUseCache;
     property UseCache : Boolean read FUseCache write SetUseCache;
+    property UseCacheAuto : Boolean read FUseCacheAuto write FUseCacheAuto;
     procedure LockList;
     procedure LockList;
     procedure UnlockList;
     procedure UnlockList;
   End;
   End;
@@ -187,7 +189,7 @@ var LElements : TBytes;
 begin
 begin
   CheckInitialized;
   CheckInitialized;
   if (AIndexStart<0) or (AInsertCount<=0) or (AIndexStart>FNextElementPosition) then raise EAbstractMemTList.Create(Format('%s AddRange %d..%d out of range 0..%d',[ClassName,AIndexStart,AIndexStart+AInsertCount,FNextElementPosition-1]));
   if (AIndexStart<0) or (AInsertCount<=0) or (AIndexStart>FNextElementPosition) then raise EAbstractMemTList.Create(Format('%s AddRange %d..%d out of range 0..%d',[ClassName,AIndexStart,AIndexStart+AInsertCount,FNextElementPosition-1]));
-  if (UseCacheData) then begin
+  if (UseCacheData(True)) then begin
     if (Length(FCacheData)-FCacheDataUsedBytes)< (AInsertCount*4) then begin
     if (Length(FCacheData)-FCacheDataUsedBytes)< (AInsertCount*4) then begin
       // Increase
       // Increase
       if (FElementsOfEachBlock>AInsertCount) then i := FElementsOfEachBlock
       if (FElementsOfEachBlock>AInsertCount) then i := FElementsOfEachBlock
@@ -262,6 +264,7 @@ begin
   FCacheUpdated := False;
   FCacheUpdated := False;
   FCacheDataLoaded := False;
   FCacheDataLoaded := False;
   FCacheDataUsedBytes := 0;
   FCacheDataUsedBytes := 0;
+  FUseCacheAuto := True;
 
 
   FAbstractMem := AAbstractMem;
   FAbstractMem := AAbstractMem;
   FInitialZone.Clear;
   FInitialZone.Clear;
@@ -407,7 +410,7 @@ begin
   Result := 0;
   Result := 0;
   FAbstractMemTListLock.Acquire;
   FAbstractMemTListLock.Acquire;
   try
   try
-  if (UseCacheData) then begin
+  if (UseCacheData(False)) then begin
     if (AIndex<0) or (AIndex>=FNextElementPosition) then raise EAbstractMemTList.Create(Format('%s index %d out of range 0..%d',[ClassName,AIndex,FNextElementPosition-1]));
     if (AIndex<0) or (AIndex>=FNextElementPosition) then raise EAbstractMemTList.Create(Format('%s index %d out of range 0..%d',[ClassName,AIndex,FNextElementPosition-1]));
     Move( FCacheData[AIndex*4], Result, 4);
     Move( FCacheData[AIndex*4], Result, 4);
   end else begin
   end else begin
@@ -473,7 +476,7 @@ begin
   FAbstractMemTListLock.Acquire;
   FAbstractMemTListLock.Acquire;
   try
   try
   AddRange(AIndex,1);
   AddRange(AIndex,1);
-  if (UseCacheData) then begin
+  if (UseCacheData(True)) then begin
     Move(APosition, FCacheData[AIndex*4], 4);
     Move(APosition, FCacheData[AIndex*4], 4);
     FCacheUpdated := True;
     FCacheUpdated := True;
   end else begin
   end else begin
@@ -527,7 +530,7 @@ begin
     else raise EAbstractMemTList.Create(Format('%s remove %d..%d out of range (NO ELEMENTS)',[ClassName,AIndexStart,AIndexStart + ARemoveCount -1]))
     else raise EAbstractMemTList.Create(Format('%s remove %d..%d out of range (NO ELEMENTS)',[ClassName,AIndexStart,AIndexStart + ARemoveCount -1]))
   end;
   end;
 
 
-  if (UseCacheData) then begin
+  if (UseCacheData(True)) then begin
     if (AIndexStart+ARemoveCount < FNextElementPosition) then begin
     if (AIndexStart+ARemoveCount < FNextElementPosition) then begin
       Move(FCacheData[(AIndexStart + ARemoveCount) *4],
       Move(FCacheData[(AIndexStart + ARemoveCount) *4],
            FCacheData[(AIndexStart) *4],
            FCacheData[(AIndexStart) *4],
@@ -591,7 +594,7 @@ var LBlockPointer, LPreviousBlockPointer : TAbstractMemPosition;
 begin
 begin
   FAbstractMemTListLock.Acquire;
   FAbstractMemTListLock.Acquire;
   try
   try
-  if (UseCacheData) then begin
+  if (UseCacheData(True)) then begin
     Move( Value, FCacheData[AIndex*4], 4);
     Move( Value, FCacheData[AIndex*4], 4);
     FCacheUpdated := True;
     FCacheUpdated := True;
   end else begin
   end else begin
@@ -624,9 +627,10 @@ begin
   FAbstractMemTListLock.Release;
   FAbstractMemTListLock.Release;
 end;
 end;
 
 
-function TAbstractMemTList.UseCacheData: Boolean;
+function TAbstractMemTList.UseCacheData(AWillUpdateData : Boolean): Boolean;
 begin
 begin
-  if FUseCache then begin
+  if (FUseCache) or ((AWillUpdateData) and (FUseCacheAuto)) then begin
+    FUseCache := True;
     Result := True;
     Result := True;
     if Not FCacheDataLoaded then begin
     if Not FCacheDataLoaded then begin
       FCacheDataLoaded := True;
       FCacheDataLoaded := True;

+ 1 - 1
src/pascalcoin_daemon.ini

@@ -55,7 +55,7 @@ DATAFOLDER=
 ;Maximum megabytes in memory as a cache - Default 100
 ;Maximum megabytes in memory as a cache - Default 100
 ABSTRACTMEM_MAX_CACHE_MB=
 ABSTRACTMEM_MAX_CACHE_MB=
 ;ABSTRACTMEM_USE_CACHE_ON_LISTS : Boolean
 ;ABSTRACTMEM_USE_CACHE_ON_LISTS : Boolean
-;Set to true (1) to allow save lists on cache or false (0) - Default False
+;Set to true (1) to allow save lists on cache or false (0) - Default True
 ABSTRACTMEM_USE_CACHE_ON_LISTS=
 ABSTRACTMEM_USE_CACHE_ON_LISTS=
 ;ABSTRACTMEM_CACHE_MAX_ACCOUNTS : Integer
 ;ABSTRACTMEM_CACHE_MAX_ACCOUNTS : Integer
 ;Max number of accounts to store at cache - Default 10000
 ;Max number of accounts to store at cache - Default 10000