Open ytcheng opened 11 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.
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:
Effortless Maintenance: Developers won't have to manually clear the cache every time a source file is modified, reducing the risk of overlooking updates.
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.
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.