phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

[NFR]: Automatic Expiration of Phalcon\Annotations Cache Based on Source File Modification Time #16473

Open ytcheng opened 11 months ago

ytcheng commented 11 months ago

Description:

Currently, in the Phalcon\Annotations component, various adapters rely on manual cache clearing to update the annotations cache. I propose implementing an automatic mechanism that checks the modification time of the source files and automatically expires the cache when changes are detected. This would eliminate the need for manual intervention to keep the annotations cache up-to-date.

Benefits:

  1. Effortless Maintenance: Developers won't have to manually clear the cache every time a source file is modified, reducing the risk of overlooking updates.

  2. Real-time Reflection: Automatic cache expiration ensures that annotations reflect the most recent changes in the source code, providing an accurate representation of the current state of the application.

  3. Improved Development Workflow: This enhancement streamlines the development workflow by removing the burden of cache management, allowing developers to focus more on coding and less on cache-related tasks.

Implementation Suggestion:

Revise each Phalcon\Annotations adapter to inspect the modification time of associated source files each time annotations are accessed. If a change is detected, automatically invalidate the cache related to the modified file. This approach ensures that the cache remains synchronized with the latest changes in the source code without relying on periodic, scheduled checks.

Additional Consideration:

Allow developers to configure the frequency of these checks or provide a sensible default that balances real-time reflection with minimal performance impact.

Note:

I believe this enhancement would contribute to a more seamless development experience with Phalcon\Annotations, and I look forward to hearing the community's thoughts and feedback on this proposal.

noone-silent commented 10 months ago

Implementation Suggestion:

Revise each Phalcon\Annotations adapter to inspect the modification time of associated source files each time annotations are accessed. If a change is detected, automatically invalidate the cache related to the modified file. This approach ensures that the cache remains synchronized with the latest changes in the source code without relying on periodic, scheduled checks.

Wouldn't that render all caching useless? If you have to check the file, then you can actually also parse it.

If you are developing, there are flags to recheck a view or annotations or to keep them in memory per request. If you go production, you should invalidate all caches and regenerate it only once for the current release. Most people I know have this in their CI or release scripts.

If you just talk about local development, you can just use other Adapters like Memory or write a cli task to invalidate caches.