#1 2014-09-20 21:36:25

Sabbiolina
Member
Registered: 2014-05-20
Posts: 120

TSQLRestCache.CachedEntries improvement/safe

Hi AB

function TSQLRestCache.CachedEntries: cardinal;
var i,j: integer;
begin
  result := 0;
  if self<>nil then
    for i := 0 to high(fCache) do
      with fCache[i] do
      if CacheEnable then
      for j := 0 to Count-1 do
        if Values[j].TimeStamp64<>0 then
          inc(result);
end;

given that the cycle works with Values [] would be better to put it under CriticalSection:



function TSQLRestCache.CachedEntries: cardinal;
var i,j: integer;
begin
 EnterCriticalSection(Mutex);
 try
  result := 0;
  if self<>nil then
    for i := 0 to high(fCache) do
      with fCache[i] do
      if CacheEnable then
      for j := 0 to Count-1 do
        if Values[j].TimeStamp64<>0 then
          inc(result);

  finally
    LeaveCriticalSection(Mutex);
  end;
end;

also
function TSQLRestCache.CachedEntries: cardinal;

Offline

#2 2014-09-21 08:12:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: TSQLRestCache.CachedEntries improvement/safe

Indeed.

We have enhanced TSQLRestCache.CachedEntries and TSQLRestCache.CachedMemory to be thread-safe.
See http://synopse.info/fossil/info/4fd6484a03e

Offline

Board footer

Powered by FluxBB