Einzelnen Beitrag anzeigen

Perlsau
(Gast)

n/a Beiträge
 
#3

AW: [ADO] MaxRecords bzw. CacheSize

  Alt 30. Mär 2014, 21:44
Gerade ausprobiert, weil zuvor noch nie verwendet:

Setzt man MaxRecords auf einen Wert größer 0, wird in jedem Fall nur die gesetze Anzahl an Records geholt. Mehr geht nicht, bis MaxRecords auf einen größeren Wert gesetzt wurde.

Beläßt man dagegen MaxRecords auf 0 und setzt CacheSize z.B. auf 5 statt 1, sollte laut Online-Hilfe weitere Datensätze erst nachgeladen werden, nachdem sie angefordert wurden. Bei Aktivieren der Datenmenge sollten daher nur 5 Datensätze im Puffer stehen. Leider hab ich keine Ahnung, wie man das nachprüfen kann, denn beim erstmaligen Abruf von RecordCount fordert man ja gleich mal alle Datensätze an.

In der Online-Hilfe wird der Puffer auch als Zwischenspeicher beschrieben, der keine Datensätze enthalten soll, "die von anderen Benutzern der Daten gleichzeitig vorgenommen wurden" – doch m.W.n. gilt das generell für alle im Speicher von Datasets existierenden Datenmengen.

Ich gehe daher davon aus, daß es sich bei CacheSize einfach um die Menge an Datensätzen handelt, die bei Bedarf nachgeladen werden: Sobald man hinter den letzten geladenen Record kommt, werden weitere – in meinem Beispiel 5 – Datensätze nachgeladen. Meine Vermutung finde ich durch diesen Beitrag bei StackOverFlow bestätigt:

CacheSize

Delphi's and ADO's default cache size for a RecordSet is 1. That's 1 record. This works in combination with the cursor type. The cachesize tells the RecordSet how many records to fetch and store at a time.

When you issue a command like Next (really MoveNext in ADO) with a cache size of 1, the RecordSet only has the current record in memory, so when it fetches that next record, it must request it from the provider again. If the cursor is not Static, that gives the provider the opportunity to get the latest data before returning the next record. So, a size of 1 makes sense for Keyset or Dynamic, because you want the provider to be able to get you the updated data.

Obviously, with a value of 1, there's communication between the provider and RecordSet each time move the cursor. Well, that's overhead that we don't want if the cursor type is static. So, increasing your cache size will reduce the number of round trips between the RecordSet and the provider. This also increases your memory requirements, but it should be faster.

Also note that with a cache size greater than 1 for Keyset cursors, if the record that you want is in the cache, it won't request it from the provider again, which means that you won't see the updates.

Geändert von Perlsau (30. Mär 2014 um 21:46 Uhr)
  Mit Zitat antworten Zitat