Doctrine 2 Cache: Can I use cache with Repository::find*()?

北战南征 提交于 2020-01-13 10:22:17

问题


I am new to caching. From the docs, I can use caching with queries, but what about methods like

$em->find('Application\Models\project', 1);

回答1:


If you search for an automatism, i think the awnser is no, their is no such thing. I was searching for something like this my self. You can wrap find(...) in a method of a service class, getProjectById($id) and do caching inside this method your self. But then you need a save() method too, to clear-cache for specific id after flushing.




回答2:


As Christian pointed out you can do query caching yourself, with the overhead of having to purge the cache.

One other note, as I've found myself looking through the EntityRepository class. The find() method will check the identity map based on id, so if you do 2 find() calls for the same entity in the same request doctrine should return the subsequent hits from the memory of the webserver.



来源:https://stackoverflow.com/questions/4841281/doctrine-2-cache-can-i-use-cache-with-repositoryfind

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!