What is the difference between local and distributed environments and cache?

It is not clear from the Memory cache documentation what is the difference between “local” and “distributed”.

If I am running Nextcloud not on a VPS (but I have an access to all config files and terminal via CPanel), what do I need to set in the config.php? Local or distributed cache? Or both?

Do I use a “local” environment or a “distributed”?

This article might answer your question:

The question is more in which situation Nextcloud uses which cache. When multiple webservers, e.g. behind a load balancer, run the same (synced) Nextcloud code and accessing a shared database server, it makes sense that they access a shared cache as well to avoid caching the same data multiple times. On the other hand, accessing a shared cache via network connections is of course slower than accessing a local memory cache like APCu or even a local Redis server via UNIX domain socket. Nextcloud must follow some logic to know which data can be cached safely across multiple webservers/systems and which data must be stored only for the local system. Furthermore it must decide in which case sharing the cache outweighs the performance decrease on access. For small files with short TTL it makes less sense, for large files with longer TTL is makes more sense, since more memory is shared and the data is more likely used by other instances.

Understanding how Nextcloud implements this logic would be interesting. I guess there is an API which apps can use, so that each app decides via own code which cache to use for what.

Btw, when the distributed cache is not defined, internally the defined local cache is used for it, which means that all data is written to the local cache then. This totally makes sense when you run a single Nextcloud instance on a single webserver system.