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.

38 lines
769 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. isStreaming := true
  16. if rp.lastReadOffset > offset {
  17. isStreaming = false
  18. }
  19. if rp.lastReadOffset == -1 {
  20. if offset != 0 {
  21. isStreaming = false
  22. }
  23. }
  24. rp.lastReadOffset = offset
  25. rp.isStreaming = isStreaming
  26. }
  27. func (rp *ReaderPattern) IsStreamingMode() bool {
  28. return rp.isStreaming
  29. }
  30. func (rp *ReaderPattern) IsRandomMode() bool {
  31. return !rp.isStreaming
  32. }