Hey All,
I'm planning to add a persistant cache layer to my app's orm package and just wanted to get feedback on my thoughts before diving into code.
What I'm planning to do is override the Orm\Model class and modify the cached_object() method. From what it looks like that method already caches the objects for the current runtime by their class name and primary key so this is pretty much the perfect place for checking the persistant cache (via the cache class). Upon save() of a record that record's id would be cleared from the cache (i dont know if there is a method that currently does this for the runtime cache, if so please point it out).
What I wanted to know is if this approach will work with relations also? I know it wouldn't work for using joins, but in my head I can see it working for lazy loading the relations because they would be using a primary key which is exactly what the cache would rely on...
Let me know if you can think of a better way to do this. I've just started looking through the orm's source so bear with me if I didn't fully understand how that all works.
--Tom
I don't really think that is the way to go, runtime caching is something very different (it's optimization really, not actually caching) from persistant caching. I would suggest approaching this like query caching: cache output by a key based on the state of an Orm\Query object just before execution.
It'll have some problems though: the Orm expects each object to only exist once in runtime, when fetching objects from cache they may come into existance a second time (thus one row existing as 2 separate objects because one was taken from cache) - this is what the runtime caching prevents and would probably need extending in some way as well.
Good luck.