I've implemented Redis caching on a Symfony2 project. Now I want to cache the results of find() and findBy() methods for some entities and keep them for specific TTL in Redis(like one week or until the next flush).
My questions are:
- Do you think is a good practice to cache entities like this?
- I was thinking to serialize the results and store them in a key something like this:
for findBy():
- cache_key:default:entity:entityId
- value: serialized object
for findBy(array $criteria ...)
- key: serialized criteria
- value: serialized result
I have an event listener for the onFlush() event, which invalidates the cache for specific entities.
Do you think is a good aproach? Is there something I should watch out for? Thank you