Skip to content
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

doctrine/cache sunset // find replacement #217

Closed
arhimede opened this issue Jan 31, 2024 · 12 comments
Closed

doctrine/cache sunset // find replacement #217

arhimede opened this issue Jan 31, 2024 · 12 comments
Assignees

Comments

@arhimede
Copy link
Member

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
Copy link
Member Author

arhimede commented Feb 6, 2024

@arhimede
Copy link
Member Author

arhimede commented Feb 6, 2024

Option 2:
extend dot-cache with the missing functions

@arhimede
Copy link
Member Author

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

@arhimede
Copy link
Member Author

this is an example of symfony/cache implementation
Casilium/casilium@12bf085

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

@arhimede
Copy link
Member Author

@OnitaAndrei
Copy link
Member

Tested and works just fine

@arhimede
Copy link
Member Author

@bidi47 pelase test in the API if it is working

@bidi47
Copy link
Collaborator

bidi47 commented Feb 29, 2024

solved in dotkernel/api#227

@arhimede
Copy link
Member Author

Image

@arhimede
Copy link
Member Author

why access and modify are 1 true year ahead ?

@alexmerlin
Copy link
Member

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
Copy link
Member Author

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

'default_life_time' => 86400,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

5 participants