dotkernel / admin

DotKernel Admin Application, built on top of Mezzio microframework and using Laminas components.ezzio for branch 2 and above.
https://admin5.dotkernel.net
MIT License
26 stars 5 forks source link

doctrine/cache sunset // find replacement #217

Closed arhimede closed 6 months ago

arhimede commented 8 months ago

we are cache-ing the doctrine stuff using the code , in local.php

'orm_default' => [ // it is recommended to disable doctrine cache on development // just comment any type of cache you don't want to be applied on development 'query_cache' => PhpFileCache::class, 'metadata_cache' => PhpFileCache::class, 'result_cache' => PhpFileCache::class,

and we recommend the following cache policy: https://www.dotkernel.com/how-to/doctrine-cache-in-mezzio-and-dotkernel/

Now, the problem is that the function PhpFileCache does not exists anymore we need to replace it somehow ..

maybe dot-cache ressurected ?

arhimede commented 7 months ago

Option 1: to use symfony cache https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/reference/caching.html

arhimede commented 7 months ago

Option 2: extend dot-cache with the missing functions

arhimede commented 7 months ago

let's analyse this package too https://github.com/PHPSocialNetwork/phpfastcache

arhimede commented 7 months ago

this is an example of symfony/cache implementation https://github.com/Casilium/casilium/commit/12bf0854ad8ac8e9b88764cf79a3c0dd584d1513

we should investigate if we use this in dotkernel/dot-cache or directly

arhimede commented 7 months ago

https://www.dotkernel.com/dotkernel/doctrine-cache-using-symfony-cache/

@OnitaAndrei please test

OnitaAndrei commented 7 months ago

Tested and works just fine

arhimede commented 7 months ago

@bidi47 pelase test in the API if it is working

bidi47 commented 7 months ago

solved in https://github.com/dotkernel/api/pull/227

arhimede commented 6 months ago

Image

arhimede commented 6 months ago

why access and modify are 1 true year ahead ?

alexmerlin commented 6 months ago

Short answer

If there is no default lifetime configured, Symfony Cache touches the cached item it just created and sets its modification time to +1 year in the future.

By setting default_life_time in config/autoload/doctrine.global.php under doctrine->cache->filesystem, we can control the cache items' expiration time (which, will still be set to the future). The below example sets default lifetime to 86400 seconds (=1 day) (file mtime will be today + 1 day):


return [
    'doctrine' => [
        'cache' => [
            'filesystem' => [
                'class' => FilesystemAdapter::class,
                'directory' => getcwd() . '/data/cache',
                'namespace' => 'doctrine',
                'default_life_time' => 86400,
            ],
        ],
    ],
];

Long answer

When Doctrine's EntityManager tries to load metadata for an entity, vendor/doctrine/persistence/src/Persistence/Mapping/AbstractClassMetadataFactory.php->getMetadataFor is executed. If no metadata was found in the cache, the entity metadata is read and saved to the cache by calling $this->cache->commit();. After jumping through a couple of interface implementations, the cache is finally written at: symfony/cache/Traits/FilesystemCommonTrait.php:106 where, after write is complete, the following code is executed

touch($tmp, $expiresAt ?: time() + 31556952); // 1 year in seconds

adding 1 year to the cache file's modification time.

If someone is interested, I traced the steps to follow the request:

arhimede commented 6 months ago

In conclusion, we will not add the doctrine configuration key:

'default_life_time' => 86400,