github.com/artpar/rclone@v1.67.3/docs/content/cache.md (about) 1 --- 2 title: "Cache" 3 description: "Rclone docs for cache remote" 4 versionIntroduced: "v1.39" 5 status: Deprecated 6 --- 7 8 # {{< icon "fa fa-archive" >}} Cache 9 10 The `cache` remote wraps another existing remote and stores file structure 11 and its data for long running tasks like `rclone mount`. 12 13 ## Status 14 15 The cache backend code is working but it currently doesn't 16 have a maintainer so there are [outstanding bugs](https://github.com/artpar/artpar/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3A%22Remote%3A+Cache%22) which aren't getting fixed. 17 18 The cache backend is due to be phased out in favour of the VFS caching 19 layer eventually which is more tightly integrated into rclone. 20 21 Until this happens we recommend only using the cache backend if you 22 find you can't work without it. There are many docs online describing 23 the use of the cache backend to minimize API hits and by-and-large 24 these are out of date and the cache backend isn't needed in those 25 scenarios any more. 26 27 ## Configuration 28 29 To get started you just need to have an existing remote which can be configured 30 with `cache`. 31 32 Here is an example of how to make a remote called `test-cache`. First run: 33 34 rclone config 35 36 This will guide you through an interactive setup process: 37 38 ``` 39 No remotes found, make a new one? 40 n) New remote 41 r) Rename remote 42 c) Copy remote 43 s) Set configuration password 44 q) Quit config 45 n/r/c/s/q> n 46 name> test-cache 47 Type of storage to configure. 48 Choose a number from below, or type in your own value 49 [snip] 50 XX / Cache a remote 51 \ "cache" 52 [snip] 53 Storage> cache 54 Remote to cache. 55 Normally should contain a ':' and a path, e.g. "myremote:path/to/dir", 56 "myremote:bucket" or maybe "myremote:" (not recommended). 57 remote> local:/test 58 Optional: The URL of the Plex server 59 plex_url> http://127.0.0.1:32400 60 Optional: The username of the Plex user 61 plex_username> dummyusername 62 Optional: The password of the Plex user 63 y) Yes type in my own password 64 g) Generate random password 65 n) No leave this optional password blank 66 y/g/n> y 67 Enter the password: 68 password: 69 Confirm the password: 70 password: 71 The size of a chunk. Lower value good for slow connections but can affect seamless reading. 72 Default: 5M 73 Choose a number from below, or type in your own value 74 1 / 1 MiB 75 \ "1M" 76 2 / 5 MiB 77 \ "5M" 78 3 / 10 MiB 79 \ "10M" 80 chunk_size> 2 81 How much time should object info (file size, file hashes, etc.) be stored in cache. Use a very high value if you don't plan on changing the source FS from outside the cache. 82 Accepted units are: "s", "m", "h". 83 Default: 5m 84 Choose a number from below, or type in your own value 85 1 / 1 hour 86 \ "1h" 87 2 / 24 hours 88 \ "24h" 89 3 / 24 hours 90 \ "48h" 91 info_age> 2 92 The maximum size of stored chunks. When the storage grows beyond this size, the oldest chunks will be deleted. 93 Default: 10G 94 Choose a number from below, or type in your own value 95 1 / 500 MiB 96 \ "500M" 97 2 / 1 GiB 98 \ "1G" 99 3 / 10 GiB 100 \ "10G" 101 chunk_total_size> 3 102 Remote config 103 -------------------- 104 [test-cache] 105 remote = local:/test 106 plex_url = http://127.0.0.1:32400 107 plex_username = dummyusername 108 plex_password = *** ENCRYPTED *** 109 chunk_size = 5M 110 info_age = 48h 111 chunk_total_size = 10G 112 ``` 113 114 You can then use it like this, 115 116 List directories in top level of your drive 117 118 rclone lsd test-cache: 119 120 List all the files in your drive 121 122 rclone ls test-cache: 123 124 To start a cached mount 125 126 rclone mount --allow-other test-cache: /var/tmp/test-cache 127 128 ### Write Features ### 129 130 ### Offline uploading ### 131 132 In an effort to make writing through cache more reliable, the backend 133 now supports this feature which can be activated by specifying a 134 `cache-tmp-upload-path`. 135 136 A files goes through these states when using this feature: 137 138 1. An upload is started (usually by copying a file on the cache remote) 139 2. When the copy to the temporary location is complete the file is part 140 of the cached remote and looks and behaves like any other file (reading included) 141 3. After `cache-tmp-wait-time` passes and the file is next in line, `rclone move` 142 is used to move the file to the cloud provider 143 4. Reading the file still works during the upload but most modifications on it will be prohibited 144 5. Once the move is complete the file is unlocked for modifications as it 145 becomes as any other regular file 146 6. If the file is being read through `cache` when it's actually 147 deleted from the temporary path then `cache` will simply swap the source 148 to the cloud provider without interrupting the reading (small blip can happen though) 149 150 Files are uploaded in sequence and only one file is uploaded at a time. 151 Uploads will be stored in a queue and be processed based on the order they were added. 152 The queue and the temporary storage is persistent across restarts but 153 can be cleared on startup with the `--cache-db-purge` flag. 154 155 ### Write Support ### 156 157 Writes are supported through `cache`. 158 One caveat is that a mounted cache remote does not add any retry or fallback 159 mechanism to the upload operation. This will depend on the implementation 160 of the wrapped remote. Consider using `Offline uploading` for reliable writes. 161 162 One special case is covered with `cache-writes` which will cache the file 163 data at the same time as the upload when it is enabled making it available 164 from the cache store immediately once the upload is finished. 165 166 ### Read Features ### 167 168 #### Multiple connections #### 169 170 To counter the high latency between a local PC where rclone is running 171 and cloud providers, the cache remote can split multiple requests to the 172 cloud provider for smaller file chunks and combines them together locally 173 where they can be available almost immediately before the reader usually 174 needs them. 175 176 This is similar to buffering when media files are played online. Rclone 177 will stay around the current marker but always try its best to stay ahead 178 and prepare the data before. 179 180 #### Plex Integration #### 181 182 There is a direct integration with Plex which allows cache to detect during reading 183 if the file is in playback or not. This helps cache to adapt how it queries 184 the cloud provider depending on what is needed for. 185 186 Scans will have a minimum amount of workers (1) while in a confirmed playback cache 187 will deploy the configured number of workers. 188 189 This integration opens the doorway to additional performance improvements 190 which will be explored in the near future. 191 192 **Note:** If Plex options are not configured, `cache` will function with its 193 configured options without adapting any of its settings. 194 195 How to enable? Run `rclone config` and add all the Plex options (endpoint, username 196 and password) in your remote and it will be automatically enabled. 197 198 Affected settings: 199 - `cache-workers`: _Configured value_ during confirmed playback or _1_ all the other times 200 201 ##### Certificate Validation ##### 202 203 When the Plex server is configured to only accept secure connections, it is 204 possible to use `.plex.direct` URLs to ensure certificate validation succeeds. 205 These URLs are used by Plex internally to connect to the Plex server securely. 206 207 The format for these URLs is the following: 208 209 `https://ip-with-dots-replaced.server-hash.plex.direct:32400/` 210 211 The `ip-with-dots-replaced` part can be any IPv4 address, where the dots 212 have been replaced with dashes, e.g. `127.0.0.1` becomes `127-0-0-1`. 213 214 To get the `server-hash` part, the easiest way is to visit 215 216 https://plex.tv/api/resources?includeHttps=1&X-Plex-Token=your-plex-token 217 218 This page will list all the available Plex servers for your account 219 with at least one `.plex.direct` link for each. Copy one URL and replace 220 the IP address with the desired address. This can be used as the 221 `plex_url` value. 222 223 ### Known issues ### 224 225 #### Mount and --dir-cache-time #### 226 227 --dir-cache-time controls the first layer of directory caching which works at the mount layer. 228 Being an independent caching mechanism from the `cache` backend, it will manage its own entries 229 based on the configured time. 230 231 To avoid getting in a scenario where dir cache has obsolete data and cache would have the correct 232 one, try to set `--dir-cache-time` to a lower time than `--cache-info-age`. Default values are 233 already configured in this way. 234 235 #### Windows support - Experimental #### 236 237 There are a couple of issues with Windows `mount` functionality that still require some investigations. 238 It should be considered as experimental thus far as fixes come in for this OS. 239 240 Most of the issues seem to be related to the difference between filesystems 241 on Linux flavors and Windows as cache is heavily dependent on them. 242 243 Any reports or feedback on how cache behaves on this OS is greatly appreciated. 244 245 - https://github.com/artpar/artpar/issues/1935 246 - https://github.com/artpar/artpar/issues/1907 247 - https://github.com/artpar/artpar/issues/1834 248 249 #### Risk of throttling #### 250 251 Future iterations of the cache backend will make use of the pooling functionality 252 of the cloud provider to synchronize and at the same time make writing through it 253 more tolerant to failures. 254 255 There are a couple of enhancements in track to add these but in the meantime 256 there is a valid concern that the expiring cache listings can lead to cloud provider 257 throttles or bans due to repeated queries on it for very large mounts. 258 259 Some recommendations: 260 - don't use a very small interval for entry information (`--cache-info-age`) 261 - while writes aren't yet optimised, you can still write through `cache` which gives you the advantage 262 of adding the file in the cache at the same time if configured to do so. 263 264 Future enhancements: 265 266 - https://github.com/artpar/artpar/issues/1937 267 - https://github.com/artpar/artpar/issues/1936 268 269 #### cache and crypt #### 270 271 One common scenario is to keep your data encrypted in the cloud provider 272 using the `crypt` remote. `crypt` uses a similar technique to wrap around 273 an existing remote and handles this translation in a seamless way. 274 275 There is an issue with wrapping the remotes in this order: 276 {{<color red>}}**cloud remote** -> **crypt** -> **cache**{{</color>}} 277 278 During testing, I experienced a lot of bans with the remotes in this order. 279 I suspect it might be related to how crypt opens files on the cloud provider 280 which makes it think we're downloading the full file instead of small chunks. 281 Organizing the remotes in this order yields better results: 282 {{<color green>}}**cloud remote** -> **cache** -> **crypt**{{</color>}} 283 284 #### absolute remote paths #### 285 286 `cache` can not differentiate between relative and absolute paths for the wrapped remote. 287 Any path given in the `remote` config setting and on the command line will be passed to 288 the wrapped remote as is, but for storing the chunks on disk the path will be made 289 relative by removing any leading `/` character. 290 291 This behavior is irrelevant for most backend types, but there are backends where a leading `/` 292 changes the effective directory, e.g. in the `sftp` backend paths starting with a `/` are 293 relative to the root of the SSH server and paths without are relative to the user home directory. 294 As a result `sftp:bin` and `sftp:/bin` will share the same cache folder, even if they represent 295 a different directory on the SSH server. 296 297 ### Cache and Remote Control (--rc) ### 298 Cache supports the new `--rc` mode in rclone and can be remote controlled through the following end points: 299 By default, the listener is disabled if you do not add the flag. 300 301 ### rc cache/expire 302 Purge a remote from the cache backend. Supports either a directory or a file. 303 It supports both encrypted and unencrypted file names if cache is wrapped by crypt. 304 305 Params: 306 - **remote** = path to remote **(required)** 307 - **withData** = true/false to delete cached data (chunks) as well _(optional, false by default)_ 308 309 {{< rem autogenerated options start" - DO NOT EDIT - instead edit fs.RegInfo in backend/cache/cache.go then run make backenddocs" >}} 310 ### Standard options 311 312 Here are the Standard options specific to cache (Cache a remote). 313 314 #### --cache-remote 315 316 Remote to cache. 317 318 Normally should contain a ':' and a path, e.g. "myremote:path/to/dir", 319 "myremote:bucket" or maybe "myremote:" (not recommended). 320 321 Properties: 322 323 - Config: remote 324 - Env Var: RCLONE_CACHE_REMOTE 325 - Type: string 326 - Required: true 327 328 #### --cache-plex-url 329 330 The URL of the Plex server. 331 332 Properties: 333 334 - Config: plex_url 335 - Env Var: RCLONE_CACHE_PLEX_URL 336 - Type: string 337 - Required: false 338 339 #### --cache-plex-username 340 341 The username of the Plex user. 342 343 Properties: 344 345 - Config: plex_username 346 - Env Var: RCLONE_CACHE_PLEX_USERNAME 347 - Type: string 348 - Required: false 349 350 #### --cache-plex-password 351 352 The password of the Plex user. 353 354 **NB** Input to this must be obscured - see [rclone obscure](/commands/rclone_obscure/). 355 356 Properties: 357 358 - Config: plex_password 359 - Env Var: RCLONE_CACHE_PLEX_PASSWORD 360 - Type: string 361 - Required: false 362 363 #### --cache-chunk-size 364 365 The size of a chunk (partial file data). 366 367 Use lower numbers for slower connections. If the chunk size is 368 changed, any downloaded chunks will be invalid and cache-chunk-path 369 will need to be cleared or unexpected EOF errors will occur. 370 371 Properties: 372 373 - Config: chunk_size 374 - Env Var: RCLONE_CACHE_CHUNK_SIZE 375 - Type: SizeSuffix 376 - Default: 5Mi 377 - Examples: 378 - "1M" 379 - 1 MiB 380 - "5M" 381 - 5 MiB 382 - "10M" 383 - 10 MiB 384 385 #### --cache-info-age 386 387 How long to cache file structure information (directory listings, file size, times, etc.). 388 If all write operations are done through the cache then you can safely make 389 this value very large as the cache store will also be updated in real time. 390 391 Properties: 392 393 - Config: info_age 394 - Env Var: RCLONE_CACHE_INFO_AGE 395 - Type: Duration 396 - Default: 6h0m0s 397 - Examples: 398 - "1h" 399 - 1 hour 400 - "24h" 401 - 24 hours 402 - "48h" 403 - 48 hours 404 405 #### --cache-chunk-total-size 406 407 The total size that the chunks can take up on the local disk. 408 409 If the cache exceeds this value then it will start to delete the 410 oldest chunks until it goes under this value. 411 412 Properties: 413 414 - Config: chunk_total_size 415 - Env Var: RCLONE_CACHE_CHUNK_TOTAL_SIZE 416 - Type: SizeSuffix 417 - Default: 10Gi 418 - Examples: 419 - "500M" 420 - 500 MiB 421 - "1G" 422 - 1 GiB 423 - "10G" 424 - 10 GiB 425 426 ### Advanced options 427 428 Here are the Advanced options specific to cache (Cache a remote). 429 430 #### --cache-plex-token 431 432 The plex token for authentication - auto set normally. 433 434 Properties: 435 436 - Config: plex_token 437 - Env Var: RCLONE_CACHE_PLEX_TOKEN 438 - Type: string 439 - Required: false 440 441 #### --cache-plex-insecure 442 443 Skip all certificate verification when connecting to the Plex server. 444 445 Properties: 446 447 - Config: plex_insecure 448 - Env Var: RCLONE_CACHE_PLEX_INSECURE 449 - Type: string 450 - Required: false 451 452 #### --cache-db-path 453 454 Directory to store file structure metadata DB. 455 456 The remote name is used as the DB file name. 457 458 Properties: 459 460 - Config: db_path 461 - Env Var: RCLONE_CACHE_DB_PATH 462 - Type: string 463 - Default: "$HOME/.cache/rclone/cache-backend" 464 465 #### --cache-chunk-path 466 467 Directory to cache chunk files. 468 469 Path to where partial file data (chunks) are stored locally. The remote 470 name is appended to the final path. 471 472 This config follows the "--cache-db-path". If you specify a custom 473 location for "--cache-db-path" and don't specify one for "--cache-chunk-path" 474 then "--cache-chunk-path" will use the same path as "--cache-db-path". 475 476 Properties: 477 478 - Config: chunk_path 479 - Env Var: RCLONE_CACHE_CHUNK_PATH 480 - Type: string 481 - Default: "$HOME/.cache/rclone/cache-backend" 482 483 #### --cache-db-purge 484 485 Clear all the cached data for this remote on start. 486 487 Properties: 488 489 - Config: db_purge 490 - Env Var: RCLONE_CACHE_DB_PURGE 491 - Type: bool 492 - Default: false 493 494 #### --cache-chunk-clean-interval 495 496 How often should the cache perform cleanups of the chunk storage. 497 498 The default value should be ok for most people. If you find that the 499 cache goes over "cache-chunk-total-size" too often then try to lower 500 this value to force it to perform cleanups more often. 501 502 Properties: 503 504 - Config: chunk_clean_interval 505 - Env Var: RCLONE_CACHE_CHUNK_CLEAN_INTERVAL 506 - Type: Duration 507 - Default: 1m0s 508 509 #### --cache-read-retries 510 511 How many times to retry a read from a cache storage. 512 513 Since reading from a cache stream is independent from downloading file 514 data, readers can get to a point where there's no more data in the 515 cache. Most of the times this can indicate a connectivity issue if 516 cache isn't able to provide file data anymore. 517 518 For really slow connections, increase this to a point where the stream is 519 able to provide data but your experience will be very stuttering. 520 521 Properties: 522 523 - Config: read_retries 524 - Env Var: RCLONE_CACHE_READ_RETRIES 525 - Type: int 526 - Default: 10 527 528 #### --cache-workers 529 530 How many workers should run in parallel to download chunks. 531 532 Higher values will mean more parallel processing (better CPU needed) 533 and more concurrent requests on the cloud provider. This impacts 534 several aspects like the cloud provider API limits, more stress on the 535 hardware that rclone runs on but it also means that streams will be 536 more fluid and data will be available much more faster to readers. 537 538 **Note**: If the optional Plex integration is enabled then this 539 setting will adapt to the type of reading performed and the value 540 specified here will be used as a maximum number of workers to use. 541 542 Properties: 543 544 - Config: workers 545 - Env Var: RCLONE_CACHE_WORKERS 546 - Type: int 547 - Default: 4 548 549 #### --cache-chunk-no-memory 550 551 Disable the in-memory cache for storing chunks during streaming. 552 553 By default, cache will keep file data during streaming in RAM as well 554 to provide it to readers as fast as possible. 555 556 This transient data is evicted as soon as it is read and the number of 557 chunks stored doesn't exceed the number of workers. However, depending 558 on other settings like "cache-chunk-size" and "cache-workers" this footprint 559 can increase if there are parallel streams too (multiple files being read 560 at the same time). 561 562 If the hardware permits it, use this feature to provide an overall better 563 performance during streaming but it can also be disabled if RAM is not 564 available on the local machine. 565 566 Properties: 567 568 - Config: chunk_no_memory 569 - Env Var: RCLONE_CACHE_CHUNK_NO_MEMORY 570 - Type: bool 571 - Default: false 572 573 #### --cache-rps 574 575 Limits the number of requests per second to the source FS (-1 to disable). 576 577 This setting places a hard limit on the number of requests per second 578 that cache will be doing to the cloud provider remote and try to 579 respect that value by setting waits between reads. 580 581 If you find that you're getting banned or limited on the cloud 582 provider through cache and know that a smaller number of requests per 583 second will allow you to work with it then you can use this setting 584 for that. 585 586 A good balance of all the other settings should make this setting 587 useless but it is available to set for more special cases. 588 589 **NOTE**: This will limit the number of requests during streams but 590 other API calls to the cloud provider like directory listings will 591 still pass. 592 593 Properties: 594 595 - Config: rps 596 - Env Var: RCLONE_CACHE_RPS 597 - Type: int 598 - Default: -1 599 600 #### --cache-writes 601 602 Cache file data on writes through the FS. 603 604 If you need to read files immediately after you upload them through 605 cache you can enable this flag to have their data stored in the 606 cache store at the same time during upload. 607 608 Properties: 609 610 - Config: writes 611 - Env Var: RCLONE_CACHE_WRITES 612 - Type: bool 613 - Default: false 614 615 #### --cache-tmp-upload-path 616 617 Directory to keep temporary files until they are uploaded. 618 619 This is the path where cache will use as a temporary storage for new 620 files that need to be uploaded to the cloud provider. 621 622 Specifying a value will enable this feature. Without it, it is 623 completely disabled and files will be uploaded directly to the cloud 624 provider 625 626 Properties: 627 628 - Config: tmp_upload_path 629 - Env Var: RCLONE_CACHE_TMP_UPLOAD_PATH 630 - Type: string 631 - Required: false 632 633 #### --cache-tmp-wait-time 634 635 How long should files be stored in local cache before being uploaded. 636 637 This is the duration that a file must wait in the temporary location 638 _cache-tmp-upload-path_ before it is selected for upload. 639 640 Note that only one file is uploaded at a time and it can take longer 641 to start the upload if a queue formed for this purpose. 642 643 Properties: 644 645 - Config: tmp_wait_time 646 - Env Var: RCLONE_CACHE_TMP_WAIT_TIME 647 - Type: Duration 648 - Default: 15s 649 650 #### --cache-db-wait-time 651 652 How long to wait for the DB to be available - 0 is unlimited. 653 654 Only one process can have the DB open at any one time, so rclone waits 655 for this duration for the DB to become available before it gives an 656 error. 657 658 If you set it to 0 then it will wait forever. 659 660 Properties: 661 662 - Config: db_wait_time 663 - Env Var: RCLONE_CACHE_DB_WAIT_TIME 664 - Type: Duration 665 - Default: 1s 666 667 #### --cache-description 668 669 Description of the remote 670 671 Properties: 672 673 - Config: description 674 - Env Var: RCLONE_CACHE_DESCRIPTION 675 - Type: string 676 - Required: false 677 678 ## Backend commands 679 680 Here are the commands specific to the cache backend. 681 682 Run them with 683 684 rclone backend COMMAND remote: 685 686 The help below will explain what arguments each command takes. 687 688 See the [backend](/commands/rclone_backend/) command for more 689 info on how to pass options and arguments. 690 691 These can be run on a running backend using the rc command 692 [backend/command](/rc/#backend-command). 693 694 ### stats 695 696 Print stats on the cache backend in JSON format. 697 698 rclone backend stats remote: [options] [<arguments>+] 699 700 {{< rem autogenerated options stop >}}