Jump to content

Digital Ocean Load Balanced Setup with ProCache


Recommended Posts

Hi,

I want to setup ProcessWire in Digital Ocean with a load balanced setup approach. Digital Ocean droplets can have a persistend file system called "block storage volume". The problem is, this block storage volume can't be shared between droplets which leads into issues with uploads and ProCache.

I solved the uploads problem with the solution that the admin panel is only be used on the first droplets and assets (uploads) are synced with lsync to the other droplets und sessions are saved in redis.

But I am struggling with this approach with ProCache. Requests to droplets 1 should be cached (and synced to dropled 2 and 3) but requests to droplets 2 and 3 shouldnt be cached since this would break my sync I guess...

One idea I had is to set env variables on droplet 2 and 3 check the variable in _init.php and set https://processwire.com/api/ref/pro-cache/cache-on/ to false otherwise to true.

Has anybody ideas to solve this?

Link to comment
Share on other sites

In recent (4.x) versions of ProCache the docblock for ProCache::___allowCacheForPage suggest that it might be a good place to hook to prevent cache file from being created. I'd probably try hooking there and setting return value to false in case a specific env variable is defined (or not defined).

Other than that... no obvious solutions here.

  • Thanks 1
Link to comment
Share on other sites

9 hours ago, teppo said:

In recent (4.x) versions of ProCache the docblock for ProCache::___allowCacheForPage suggest that it might be a good place to hook to prevent cache file from being created. I'd probably try hooking there and setting return value to false in case a specific env variable is defined (or not defined).

Other than that... no obvious solutions here.

Thanks I will look into this and if it works I will update this post 🙂

  • Like 1
Link to comment
Share on other sites

On 2/15/2022 at 11:52 AM, teppo said:

In recent (4.x) versions of ProCache the docblock for ProCache::___allowCacheForPage suggest that it might be a good place to hook to prevent cache file from being created. I'd probably try hooking there and setting return value to false in case a specific env variable is defined (or not defined).

Other than that... no obvious solutions here.

Thanks I will look into this and if it works I will update this post 🙂

Update: Approach works 🙂

$this->addHookAfter('ProCache::allowCacheForPage', function (HookEvent $event) {
  $event->return = (!empty(\DROPLET_HOSTNAME) && (\DROPLET_HOSTNAME === "my-droplet-production-01" || \DROPLET_HOSTNAME === "my-droplet-stage-01")) ? true : false;
});

 

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...