I'm binding Memcache to Doctrine and it seems I have to useResultCache
explicitly in every query. Is it possible to make it true
by default, with the ability to useResultCache(false)
where it's not needed?
相关问题
- How to specify memcache server to Rack::Session::M
- jsp caching tag library
- How can we cache HLS video url once streamed
- Functional Test - Mock service does not persist in
- Hibernate cache level 1
相关文章
- Is there a google API to read cached content? [clo
- Why is file_get_contents faster than memcache_get?
- AWS API Gateway caching ignores query parameters
- Check if url is cached webview android
- WebView's LOAD_NO_CACHE setting still saves fi
- Symfony ONE-TO-ONE relation
- QML Loader not shows changes on .qml file
- UnitOfWork in Action Filter seems to be caching
I know this question is old, but I'll write up the best answer that comes into my mind.
1) Abstract away your dependency to interface ( i.e. - use dependency injection pattern to inject EntityManager into your class that creates queries and use EntityManagerInterface instead )
Now, either:
a) [ Better, but longer ] Create a new composition-related implementation for EntityManagerInterface, that will proxy calls to original entityManager and will set result cache flag to true:
b) [ Not as good, but shorter ] Extend the EntityManager class and override the createQuery. Remember that this in general is not a good practice and you should definitely not write anything in that class anymore but instead refactor into a) :
You can hack the Doctrine core a little by setting the default value of
$_useResultCache
toTRUE
in\Doctrine\ORM\AbstractQuery
. This will make all queries use the resultCacheDriver by default, and you can easily turn the cache off for individual queries using$query->useResultCache(FALSE)
It's a useful little hack that saves you a lot of typing, but be careful; I've found that the caching driver won't cache lazy-loaded associations that haven't been initialized (which is obvious now I think about it). Sometimes it's safer to just turn result caching on for each individual query.
Create a wrapper class/function that explicitly sets
useResultCache(true)
and use that everywhere instead of the native function.