cphalcon
cphalcon copied to clipboard
[NFR]: ORM: Model Thread Cache, AKA First Level Cache or L1 cache
Is your feature request related to a problem? Please describe. The ORM does not have a single source of truth when it fetches a new model.
That means that fetching the same model data from the database actually gives you two different instance objects of the same data.
This leads to false data, data losses, incorrect saves and longer saves.
Describe the solution you'd like A thread cache that has all the models that are in memory, if that model with that Primary key is fetched the Thread cache will return the already instance model in memory.
If the model does not exists any longer in memory then a new instance will be made with fresh data.
Describe alternatives you've considered There are none, this is by default in most ORMs, in java Hibernate it's not even an option, it is always on.
Additional context https://www.linkedin.com/advice/3/what-benefits-drawbacks-using-orm-caching https://howtodoinjava.com/hibernate/understanding-hibernate-first-level-cache-with-example/
I would describe this more has a bug than a feature, data needs to be reliable across the thread, having two objects with the same data will induce the dev into persisting wrong information or having complicated methods to circumvent this issue.