blob: 5e6ea7348a754028aea782681b865790699a76ac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package filer
type ReaderPattern struct {
isStreaming bool
lastReadOffset int64
}
// For streaming read: only cache the first chunk
// For random read: only fetch the requested range, instead of the whole chunk
func NewReaderPattern() *ReaderPattern {
return &ReaderPattern{
isStreaming: true,
lastReadOffset: -1,
}
}
func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
if rp.lastReadOffset > offset {
rp.isStreaming = false
}
if rp.lastReadOffset == -1 {
if offset != 0 {
rp.isStreaming = false
}
}
rp.lastReadOffset = offset
}
func (rp *ReaderPattern) IsStreamingMode() bool {
return rp.isStreaming
}
func (rp *ReaderPattern) IsRandomMode() bool {
return !rp.isStreaming
}
|