Most of us use cloud storage services like Google Drive, Dropbox, or OneDrive. However, I recently switched from OneDrive to Nextcloud since it prioritizes privacy, and also lets me store my files without paying a monthly subscription fee. Thanks to this, I can store sensitive files and access them from anywhere — since they're all on my local home server. Additionally, Nextcloud also facilitates easy collaboration when working on productivity apps. The built-in editing suite can be used as a replacement for Microsoft Office, which is a nice touch. While Nextcloud has been great in terms of functionality, the only slight issue I've had has been in terms of performance.

From time to time, the interface feels sluggish — especially when handling large chunks of data. I've registered multiple users on the platform, since I share it with my folks at home. That's when I realized that even with multiple users simultaneously logged into Nextcloud and accessing or uploading files, the performance takes a dip. While these are edge cases for me, slow loading and sync times can be frustrating to someone who has just made the switch. So, I decided to find a solution. After some research, I figured that setting up a Valkey cache with Nextcloud was the best way out. Turns out, it completely fixed all my performance woes. If you are a Nextcloud user, here's a simple yet effective hack to drastically improve its performance.

Adding Valkey to your setup

Modifying the right files

I've set up Nextcloud on an old laptop using Docker, so the steps mentioned here are for adding Valkey to a similar setup. The first step involves modifying the docker-compose.yml file to include a Valkey container. Navigate to the Nextcloud directory and edit the file as follows -

services:
nextcloud:
# existing Nextcloud configuration
depends_on:
- valkey
environment:
- REDIS_HOST=valkey
- REDIS_PORT=6379

valkey:
image: valkey/valkey:latest
container_name: valkey
restart: unless-stopped
volumes:
- ./valkey/data:/data
command: valkey-server --appendonly yes
networks:
- nextcloud_network

networks:
nextcloud_network:
driver: bridge

Save the file and exit. Once done, it's time to set up PHP extensions so that Nextcloud can communicate with Valkey.

Configuring Nextcloud for Valkey

Installing PHP extensions

The Docker version of Nextcloud may lack the php-redis extension, so let's add it. In your project directory, create a Dockerfile using the following command in the terminal -

nano Dockerfile

Then, add the following to it -

FROM nextcloud:latest
RUN apt-get update && apt-get install -y php-redis php-igbinary && apt-get clean

Once done, it's time to update the nextcloud service in the docker-compose.yml file once again. Make the following modifications -

nextcloud:

 build:
context: .
dockerfile: Dockerfile
#rest of your existing Nextcloud configuration

With all of this out of the way, it's time to configure Nextcloud for Valkey. We'll use some basic Docker commands to get things rolling. Rebuild the container by using the following command in the terminal -

docker compose up -d --build

Back up Nextcloud's configurations using -

cp nextcloud/config/config.php nextcloud/config/config.php.backup

Then, open the config.php file via -

nano nextcloud/config/config.php

Before the closing ); at the end, add the following -

'memcache.local' => '\OC\Memcache\APCu',
'memcache.distributed' => '\OC\Memcache\Redis',
'memcache.locking' => '\OC\Memcache\Redis',
'redis' => [
'host' => 'valkey',
'port' => 6379,
'dbindex' => 5,
'timeout' => 1.5,
],

Restart the Nextcloud container using -

docker compose restart nextcloud

Your Nextcloud interface should now magically feel faster and snappier! You can check the container status using -

docker compose ps

If the result contains both containers along with their relevant identifiers, it should indicate that both Nextcloud and Valkey are running. Once you verify it, jump into Nextcloud and perform a few tasks to see the difference. Navigate between the different menus, upload multiple files at once, download large files onto your local storage, etc. You should see that tasks that used to lag before are now noticeably smoother. If you aren't using Nextcloud already, you can also use this process when freshly deploying the container. Just merge the contents of the docker-compose.yml at the beginning with the required contents to deploy Nextcloud. If you're using a Linux distro on your server, you can clone the Valkey repository and build it on your machine.

Navigate your files and folders smoothly

Once you integrate Valkey, your Nextcloud instance should automatically feel much faster than before. You can try accessing multiple files and folders one after the other, ask several users to log in to their instance and upload files simultaneously, or even interact with the admin panel to realize how snappier it feels. This is especially useful if you have thousands of files and folders, several users, and you use Nextcloud to back up data from your computers. When working with large files, even a few seconds of savings is totally worth the slight additional effort to set up Valkey.