Answer the question
In order to leave comments, you need to log in
How to cache sql query execution data in symfony 4 + doctrine?
Good day, I’m interested in the following question:
The database has table A and table B
The data in table A is updated very often, their selection is not resource-intensive and you always need to show the current table to the user, in this case, Doctrine by default copes well by caching only the structure to the file tables.
There are no questions - everything works out of the box.
But suppose in table B, data selection is a very resource-intensive process, such a table is updated extremely rarely, and the user can be shown not the most up-to-date data.
It would be desirable without reinventing the wheel - that is, by standard means, to cache table B into a file.
Not only its structure, but also the result of the sql query.
That would not have to do a sample every time.
What are the standard solutions for table B - note that table A should not be cached in this way.
I use a bunch of symfony 4 + doctrine
PS: If you like answering off topic, you don’t need to write about the fact that the table can be optimized, I’m not stupid, I know all this, the question is specifically about managing the cache, this is the essence of the question, I want to hear about the cache and not about the need to optimize the table!
Answer the question
In order to leave comments, you need to log in
You can preconfigure caching in Symfony for Doctrine:
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '@doctrine.result_cache_pool'
doctrine:
orm:
result_cache_driver:
type: service
id: doctrine.result_cache_provider
framework:
cache:
# Redis
app: cache.adapter.redis
default_redis_provider: '%env(REDIS_URL)%'
...
->getQuery()
->useResultCache(true) // кешировать результат данного запроса
//->setResultCacheLifetime(3600) // время жизни кеша при необходимости
->getResult()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question