You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
657 B

  1. package filer
  2. type ReaderPattern struct {
  3. isSequentialCounter int64
  4. lastReadStopOffset int64
  5. }
  6. // For streaming read: only cache the first chunk
  7. // For random read: only fetch the requested range, instead of the whole chunk
  8. func NewReaderPattern() *ReaderPattern {
  9. return &ReaderPattern{
  10. isSequentialCounter: 0,
  11. lastReadStopOffset: 0,
  12. }
  13. }
  14. func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
  15. if rp.lastReadStopOffset == offset {
  16. rp.isSequentialCounter++
  17. } else {
  18. rp.isSequentialCounter--
  19. }
  20. rp.lastReadStopOffset = offset + int64(size)
  21. }
  22. func (rp *ReaderPattern) IsRandomMode() bool {
  23. return rp.isSequentialCounter >= 0
  24. }