开发者

ActiveRecord Pattern and caching?

开发者 https://www.devze.com 2022-12-22 00:28 出处:网络
I have in one project classes organized with ActivePattern (example : myObject->Load()) but now we need to implement some caching and caching 开发者_JS百科is problematic.

I have in one project classes organized with ActivePattern (example : myObject->Load()) but now we need to implement some caching and caching 开发者_JS百科is problematic.

To make it simples, the Load() method in every object call the DAL my giving the $this reference and the DAL fill up the object that all values. It works. But when we add some caching the object unserialized is a "new" object and the DAL cannot sent it back to the object because we have a reference to the object that need to be loaded. The only work around is to put the cache code inside the Load() of each object and to loop all properties from the caching object to Get the value and to Set it back to the real object.

Is there a better way to use caching with ActiveRecord Pattern?


If I understand correctly from your comment your problem is replacing this. What I would do is create a static "fetch" method on the active record class that would check cache, return if available, and if not return a new instance of the class. This will get you around having to replace this, and the only thing you have to change is the way you are loading the active record class.

0

精彩评论

暂无评论...
验证码 换一张
取 消