Doctrine 2 Cache: Can I use cache with Repository:

2019-05-02 00:21发布

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);

2条回答
时光不老,我们不散
2楼-- · 2019-05-02 00:58

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.

查看更多
聊天终结者
3楼-- · 2019-05-02 01:01

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.

查看更多
登录 后发表回答