72 {
73 # Update cache
74 foreach( array_keys( $this->cache, $offset ) as $k ) { unset($this->cache[$k]); }
75 $this->cache = array_values( $this->cache );
76 array_push( $this->cache, $offset );
77 while( count( $this->cache ) > $this->numCache ) {
78 $k = array_shift( $this->cache );
79 unset( $this->records[$k] );
80 }
81 # Now get the record
82 if( !isset( $this->records[ $offset ] ) ) {
83 if( !isset( $this->recordOffsets[$offset] ) ) {
84 for( $i = $offset - 1 ; $i > 0 ; $i-- ) {
85 if( isset( $this->recordOffsets[$i] ) ) break;
86 }
87 fseek( $this->input, $this->recordOffsets[$i], SEEK_SET );
88 while( $i < $offset ) {
90 $i++;
91 $this->recordOffsets[ $i ] = ftell( $this->input );
92 }
93 } else {
94 fseek( $this->input, $this->recordOffsets[$offset], SEEK_SET );
95 }
96 $this->records[ $offset ] = new $this->recordClass();
97 $this->records[ $offset ]->loadFromBinaryStream( $this->input );
98 if(feof($this->input)) {
99 $this->numRecords = $offset+1;
100 } else {
101 $this->recordOffsets[$offset+1] = ftell( $this->input );
102 }
103 }
104 return $this->records[ $offset ];
105 }