github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/docs/content/cache.md (about)

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