github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/vfs/vfscommon/cachemode.go (about) 1 package vfscommon 2 3 import ( 4 "fmt" 5 6 "github.com/rclone/rclone/lib/errors" 7 ) 8 9 // CacheMode controls the functionality of the cache 10 type CacheMode byte 11 12 // CacheMode options 13 const ( 14 CacheModeOff CacheMode = iota // cache nothing - return errors for writes which can't be satisfied 15 CacheModeMinimal // cache only the minimum, eg read/write opens 16 CacheModeWrites // cache all files opened with write intent 17 CacheModeFull // cache all files opened in any mode 18 ) 19 20 var cacheModeToString = []string{ 21 CacheModeOff: "off", 22 CacheModeMinimal: "minimal", 23 CacheModeWrites: "writes", 24 CacheModeFull: "full", 25 } 26 27 // String turns a CacheMode into a string 28 func (l CacheMode) String() string { 29 if l >= CacheMode(len(cacheModeToString)) { 30 return fmt.Sprintf("CacheMode(%d)", l) 31 } 32 return cacheModeToString[l] 33 } 34 35 // Set a CacheMode 36 func (l *CacheMode) Set(s string) error { 37 for n, name := range cacheModeToString { 38 if s != "" && name == s { 39 *l = CacheMode(n) 40 return nil 41 } 42 } 43 return errors.Errorf("Unknown cache mode level %q", s) 44 } 45 46 // Type of the value 47 func (l *CacheMode) Type() string { 48 return "CacheMode" 49 }