-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fall back to NullCache on CLI calls if configured cache is not available #27608
Comments
Ref #25770 (comment)
While that is true, it does not fully work as per #25770 (comment)
|
To sum up things here:
if (!class_exists($localCacheClass) || !$localCacheClass::isAvailable()) {
if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
// CLI should not hard-fail on broken memcache but fallback to NullCache
$localCacheClass = self::NULL_CACHE;
$this->logger->info($missingCacheMessage, [
'class' => $localCacheClass,
'use' => 'local',
'app' => 'cli'
]);
If I'm not mistaken, there is no direct way that a CLI call can interact with the cache of running PHP instance, and to me this looks perfectly as it should be, for all privacy and security reasons. An indirect way would be a server-side API, so that the CLI call sends a request to the running Nextcloud instance which then clears the cache internally, or a flag file/
Do you have a specific case in mind where this was ever intended/required? It might be nice for convenience if an external Nextcloud or app upgrade would invalidate related caches, but that's a known limitation depending on TTL and I at least never faced an issue while intensively using the CLI. And keep in mind that APCu is THE recommended caching backend and the majority of Nextcloud users will use it, without anyone ever having the ability to use or invalidate the running PHP instance's cache from CLI. We would have recognised if this did cause any issues, that's for sure. Regarding the actual purpose of the issue, let's concentrate on whether the above suggestion would make things better or worse compared to how it is done now (after Now:
With above suggestion:
So comparing the cases, the above suggestion has no downside but preserves the Nextcloud pre-20 ability of using CLI even if the configured caching backend is not available. Furthermore it skips building/allocating the cache then and should hence usually be faster and consume less resources. A consequent alternative would be btw to always use NullCache for CLI calls, even if the configured caching backend is available. That would make things more predictable, any log could be skipped etc. |
cc @nextcloud/server for more input on this |
It took only 3 years, but here is a PR to re-implement the NullCache fallback for non-PHPUnit CLI calls: #46151 |
How to use GitHub
Is your feature request related to a problem? Please describe.
After #25440, Nextcloud requires the configured memory cache (
config.php
>memcache.local
) to be available as well for CLI calls. By default PHP APCu is disabled for CLI calls, which already did produce a log entry in the past and it was always recommended to enable it (apc.enable_cli=1
) to avoid potential issues with some background jobs. It is however not optimal to initiate a caching instance for a CLI command, which usually does not repeatedly read the same resource, so that building the cache slows down the whole call more than the benefit of having involved resources cached. Also this can lead to a significant increase of memory usage, when CLI calls stack, each with an own cache instance. This matter has been further discussed in #25770.Describe the solution you'd like
In case of CLI falls, if the configured memory cache is not available (
apc.enable_cli=0
and alike), fallback to NullCache, as if no cache was configured (memcache.local
unset ornone
).Describe alternatives you've considered
An alternative would be to use NullCache in the first place on all CLI calls, ignoring the
memcache.local
value. But it won't have any benefit as long as the backend itself (PHP module or server) has been initialised or is running anyway.Additional context
For me, the related code block already looks like it does what I suggest, but obviously it does not, as otherwise the loop, worked around with #25770 wouldn't exist. Here is how I understand the code (obviously wrong), and hopefully someone can point me to the thing I misinterpret:
This NullCache is applied for local and distributed cache, as long as no other one has been configured.
isAvailable()
but returns null/false on everyget()
/hasKey()
.!class_exists($localCacheClass)
or it is not available!$localCacheClass::isAvailable()
and it is a CLI call(\OC::$CLI && !defined('PHPUNIT_RUN'))
, assign theNULL_CACHE
variable, and hence the "NullCache" as local and distributed caching backend respectively.apc.enable_cli=0
), the NullCache backend will be used instead. As it is a valid caching backend (though a dummy) as well and itsisAvailable()
always returns true, the same condition can never be met and hence the loop described in Don't allow executing cli if cache backend is unavailable #25770 should not exist.The text was updated successfully, but these errors were encountered: