-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FIX Ensure cache is shared between CLI and webserver #11300
FIX Ensure cache is shared between CLI and webserver #11300
Conversation
82cf8c1
to
502fee6
Compare
public function create($service, array $params = []); | ||
public function create(string $service, array $params = []): ?object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't strictly necessary - but it does make things a bit clearer. Can remove this change if it's causing headaches.
private function isSupported(): bool | ||
{ | ||
static $isSupported = null; | ||
if (null === $isSupported) { | ||
// Need to check for CLI because Symfony won't: https://github.com/symfony/symfony/pull/25080 | ||
$isSupported = Director::is_cli() | ||
? filter_var(ini_get('apc.enable_cli'), FILTER_VALIDATE_BOOL) && ApcuAdapter::isSupported() | ||
: ApcuAdapter::isSupported(); | ||
} | ||
return $isSupported; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is moved here from DefaultCacheFactory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of this class is moved here from DefaultCacheFactory
@@ -7,7 +7,6 @@ SilverStripe\Core\Injector\Injector: | |||
constructor: | |||
args: | |||
directory: '`TEMP_PATH`' | |||
version: null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version
is effectively a flush mechanism - if the version changes, all cache with the previous version is invalidated.
Given this config isn't available when instantiating manifest cache, I've moved this to being an environment variable. In practice I don't think anyone would ever bother setting it since Silverstripe CMS has so many ways to flush cache.
c0e7664
to
f8c11d8
Compare
*/ | ||
public function create($service, array $params = []); | ||
public function create(string $service, array $params = []): CacheInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note this is PSR16 - this is intended for direct use.
f8c11d8
to
839cb92
Compare
/** | ||
* Create a PSR6-compliant cache adapter | ||
*/ | ||
public function createPsr6(string $service, array $params = []): CacheItemPoolInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSR6 specifically required so it can be bundled in a ChainAdapter
along-side the filesystem cache adapter.
This is in contrast to the create()
method which must be PSR16 for direct use.
839cb92
to
c75413f
Compare
tests/php/Core/Cache/CacheTest.php
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The YAML for these is no longer valid, and these tests would now fail if memcached isn't installed and apcu isn't enabled for CLI.
These are covered through the new DefaultCacheFactoryTest
anyway.
c75413f
to
feec1d2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes here are a natural consequence of strict typing in the Factory
interface. It's documented in the changelog.
feec1d2
to
2321737
Compare
.github/workflows/ci.yml
Outdated
phpunit_skip_suites: framework-cache-only | ||
# Ensure we test all in-memory cache factories provided in core | ||
extra_jobs: | | ||
- phpunit: true | ||
phpunit_suite: framework-cache-only | ||
install_inmemory_cache_exts: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works with the two CI PRs to ensure we install everything we need to be able to include all three in-memory cache adapters in the new DefaultCacheFactoryTest
test.
throw new RuntimeException('Redis is not supported in the current environment. Cannot use Redis cache.'); | ||
} | ||
|
||
$dsn = Environment::getEnv('SS_REDIS_DSN'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth simply having SS_IN_MEMORY_CACHE_DSN
and checking it starts with redis
instead on splitting out SS_REDIS_DSN
and SS_MEMCACHED_DSN
, given that there's only a single SS_IN_MEMORY_CACHE_FACTORY
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's cleaner if they're separate, given the factories are separate. Each factory looks for its own DSN. I wouldn't want the memcached factory to be looking for a DSN variable that's shared with Redis, that sounds messy to me.
ed04e03
to
ed321f8
Compare
Description
PhpFilesAdapter
as the default filesystem cache adapterFilesystemAdapter
only ifPhpFilesAdapter
isn't supported by both webserver and CLIRedisCacheFactory
as an option for in-memory cacheSS_MEMORY_CACHEFACTORY
environment variable for opting in to in-memory cacheApcuCacheFactory
andMemcachedCacheFactory
to use args passed intocreate()
or environment variables instead of constructor argsFactory::create()
and its subclassesThere is an edge-case drawback to this approach.
All redis/memcached cache will always use the same connection details. You couldn't for example use one redis server to cache some stuff, and another server to cache some other stuff.
The workaround for that would be to implement your own
CacheFactory
class for instantiating the cache adapter for the stuff you want on another server. So we're not locking out that possibility, just requiring a little bit more boilerplate if people want to do that.Requires
The following PRs need to be merged for CI to go green:
Issues