aimeos / aimeos-typo3

TYPO3 e-commerce extension for ultra fast online shops, scalable marketplaces, complex B2B applications and #gigacommerce
https://aimeos.org/TYPO3
GNU General Public License v3.0
372 stars 744 forks source link

[Feature] Make "Flush all caches" really fush all caches #110

Closed guelzow closed 4 years ago

guelzow commented 4 years ago

Hi everyone.

You can use the extension manager to tell Aimeos to use APCu for caching it's configuration. Sadly, there is no integration into the Flush all caches button. This can be really confusing for developers (at least it was for me).

Tobi

aimeos commented 4 years ago

Yes, such an integration would be great. Are you able to provide a PR? But then, one problem will still exist: If you have more than one web server, only the APCu cache of that web server will be flushed, which receives the HTTP request.

guelzow commented 4 years ago

Are you able to provide a PR

We are in the middle of the end of year hustle (is that the right word?). Sorry, not right now.

more than one web server

Shouldn't the load balancer handle these requests? If it doesn't, I could imagine that this would also make problems for the surrounding TYPO3. Disclaimer: I have only theoretical knowledge about a multi server setup.

aimeos commented 4 years ago

No, load balancers only forward requests to a single web server, not to all.

guelzow commented 4 years ago

Hmm, so a master/slave DB configuration with shared (caching) tables would be used?

That would mean, that we need to write one small system cache entry into the DB (timestamp?) and in the ACPu after a system cache wipe. On every request we need to check if we have the same value inside the ACPu. If not, we must assume that somebody else did a system cache wipe. We then need to wipe the ACPu and adopt the value from the DB cache.

aimeos commented 4 years ago

Not sure if that will be a resonable way to deal with that but clearing the APCu cache when doing a "clear all caches" would be a first step. Thought, TYPO3 already does that when using "Maintenance -> Flush TYPO3 and PHP Cache"

guelzow commented 4 years ago

I think we should do both:

1.) Hook into the Clear Cache:

ext_localconf.php

// Register the Aimeos-APCu-Cache-Wipe to the red-cache-wipe.
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] =
    \SomeVendor\SomeNamespace\Hooks\ClearAPCuCache::class . '->flushAPCuCache';

ClearAPCuCache.php

class ClearAPCuCache
{
    /**
     * Doing a complete ACPu wipe with the red system cache.
     *
     * @hook clearCachePostProc
     *
     * @param array $cacheType
     *   The caching type.
     * @param \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler
     *   Not used, but required for the hook.
     */
    public function flushAPCuCache($cacheType, $dataHandler)
    {
        $aimeosConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['aimeos']);

        if ($cacheType['cacheCmd'] === 'all' &&
            $aimeosConfiguration['useAPC'] === '1' &&
            function_exists('apcu_clear_cache')
        ) {
            apcu_clear_cache();
           // Missing part:
           // Write a timestamp to any of the system caches.
        }
    }
}

2.) In the Aimeos\Aimeos\Base\Config where we check if the system cache was cleared by someone else (Master/Salve DB, InstallTool, Scheduler, Admin, . . .)

TYPO3 already does that when using "Maintenance -> Flush TYPO3 and PHP Cache"

The (former) installtool can clear the ACPu cache?

aimeos commented 4 years ago

It would be best to do 1.) as static method in https://github.com/aimeos/aimeos-typo3/blob/master/Classes/Base.php Can you create a PR?

guelzow commented 4 years ago

Can you create a PR?

Done.