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.

36 lines
724 B

  1. package filer
  2. type ReaderPattern struct {
  3. isStreaming bool
  4. lastReadOffset 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. isStreaming: true,
  11. lastReadOffset: -1,
  12. }
  13. }
  14. func (rp *ReaderPattern) MonitorReadAt(offset int64, size int) {
  15. if rp.lastReadOffset > offset {
  16. rp.isStreaming = false
  17. }
  18. if rp.lastReadOffset == -1 {
  19. if offset != 0 {
  20. rp.isStreaming = false
  21. }
  22. }
  23. rp.lastReadOffset = offset
  24. }
  25. func (rp *ReaderPattern) IsStreamingMode() bool {
  26. return rp.isStreaming
  27. }
  28. func (rp *ReaderPattern) IsRandomMode() bool {
  29. return !rp.isStreaming
  30. }