Closed arhimede closed 6 months ago
Option 1: to use symfony cache https://www.doctrine-project.org/projects/doctrine-orm/en/2.17/reference/caching.html
Option 2: extend dot-cache with the missing functions
let's analyse this package too https://github.com/PHPSocialNetwork/phpfastcache
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
https://www.dotkernel.com/dotkernel/doctrine-cache-using-symfony-cache/
@OnitaAndrei please test
Tested and works just fine
@bidi47 pelase test in the API if it is working
why access and modify are 1 true year ahead ?
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,
],
],
],
];
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:
In conclusion, we will not add the doctrine configuration key:
'default_life_time' => 86400,
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 ?