silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

SPIKE: Investigate ways to get configurable cache adapter prior to loading config #11257

Open GuySartorelli opened 1 month ago

GuySartorelli commented 1 month ago

https://github.com/silverstripe/silverstripe-framework/issues/11145 points out a problem with APCu cache which is the current in-memory cache adapter. This is hard coded to be used if it's available, and not used if it's not. Other cache adapters can be configured for many things, but the manifests will always use this default setup.

If we want to be able to configure the in-memory cache to be any arbitrary PSR6/PSR16 cache adapter, we need to be able to provide that configuration prior to booting the manifests. See BaseKernel::__construct().

Timebox

2 days

Spike objectives

GuySartorelli commented 1 month ago

Some possible options Steve and I have already thought of:

GuySartorelli commented 3 days ago

Turns out there's already a SS_MANIFESTCACHE environment variable to handle this. You set that to the FQCN for the class to use (either a PSR compliant cache adapter or a class that implements the CacheFactory interface).

In practice you'd probably have to use a factory, so you can use additional env vars to configure it.

So you'd probably have a MyCustomCacheFactory extends CacheFactory, and then you'd use that both with SS_MANIFESTCACHE and in yaml replacing the DefaultCacheFactory.

It's a bit crumby though - a single yaml config would be better so you don't have to remember to set the env var for it. I'll keep digging to see if there's something else we can do. For now though that's a good fallback position.