procedure TCustomCache.RefreshCache;
var
     i:Integer;
     CurItem:TCustomCacheItem;
     UpdateAge,AccessAge:Integer;
     NeedRefresh:Boolean;
     CurTime:_SYSTEMTIME;
begin
     if not FRefreshEnable then Exit;
     GetLocalTime(CurTime);
     if ((CurTime.wHour < FRefreshFrom) or (CurTime.wHour >= FRefreshTo)) then Exit;
     FRefreshThreadCounter:=FRefreshThreadCounter + 1;
     i:=1;
     while (i <= FItemsCount) do begin
          CurItem:=GetItem(i);
          CurItem.RegisterHeadReading;
          NeedRefresh:=CurItem.FData.FUsed;
          if NeedRefresh then begin
               UpdateAge:=CurItem.GetUpdateAge;
               AccessAge:=CurItem.GetAccessAge;
               NeedRefresh:=((AccessAge <= UpdateAge) and (UpdateAge > CurItem.FData.FRefreshRate));
          end;
          CurItem.UnregisterHeadReading;
          if NeedRefresh then begin
               GetLocalTime(CurTime);
               if ((CurTime.wHour < FRefreshFrom) or (CurTime.wHour >= FRefreshTo)) then Break;
               RefreshItem(CurItem);
          end;
          i:=i + 1;
     end;
end;



function TCustomCache.FindPage(const PageCrc:DWORD; const SliceItem:TSliceItem):Boolean;
var
     i:Integer;
     CurItem:TCustomCacheItem;
     NeedRefresh:Boolean;
begin
     Result:=False;
     i:=1;
     while ((not Result) and (i <= FRealMaxItem)) do begin
          CurItem:=GetItem(i);
          NeedRefresh:=False;
          CurItem.RegisterHeadReading;
          if (CurItem.FData.FUsed and (CurItem.FData.FCrc = PageCrc)) then begin
               NeedRefresh:=FRefreshEnable and FForcedEnable;
               if NeedRefresh then NeedRefresh:=(CurItem.GetUpdateAge > CurItem.FData.FRefreshRate);
               Result:=True;
          end;
          CurItem.UnregisterHeadReading;
          if Result then begin
               if NeedRefresh then RefreshItem(CurItem);
               CurItem.RegisterBodyReading;
               CurItem.BodyToSlice(SliceItem);
               CurItem.UnregisterBodyReading;
               CurItem.BeginHeadWriting;
               GetLocalTime(CurItem.FData.FAccessTime);
               CurItem.FData.FCounter:=CurItem.FData.FCounter + 1;
               CurItem.EndHeadWriting;
          end;
          i:=i + 1;
     end;
end;


Extra Web Top