Description
TL;DR of this issue:
- Every Symfony component and bundle uses a centralized log service thanks to Monolog.
- I want the same idea applied to the Cache component.
There is a lot of work around the new Cache component lately. But in my opinion, we are not talking about "the big picture" and how to make Cache a centerpiece feature for Symfony. This is how I imagine the Cache component being used in Symfony apps:
Defining application caches
When defining one cache, Symfony names it default
automatically (same behavior as "swiftmailer" mailers and "doctrine" managers)
# app/config/config.yml
# simple cache without arguments
cache:
type: array
# equivalent to:
# cache:
# default:
# type: array
Complex caches can define arguments:
# app/config/config.yml
cache:
type: doctrine
em: my_custom_em_id
You can also define lots of different caches in a single app (in this case is mandatory to name one of them default
):
# app/config/config.yml
cache:
default:
type: array
db:
type: doctrine
em: my_custom_em_id
They are available in the application as cache.default
and cache.db
services.
The cache
service is an alias for cache.default
.
Configuring the application caches
Params such as default_lifetime
and namespace
are available for any cache type:
# app/config/config.yml
cache:
type: array
default_lifetime: 600
namespace: 'ACME__'
Using caches in Symfony components
All Symfony components define a cache
option. Its value can be:
- A boolean, to enable or disable the cache. If
true
, thedefault
cache is used:
# app/config/config.yml
framework:
validation:
cache: true
enable_annotations: true
serializer:
cache: true
property_path:
cache: true
doctrine:
orm:
cache: true
# you can also set 'metadata_cache_driver', 'result_cache_driver'
# and 'query_cache_driver' separately
- You can also set the
id
of the cache:
# app/config/config.yml
framework:
validation:
cache: db
enable_annotations: true
serializer:
cache: default
property_path:
cache: default
- It's also possible to define an array of cache ids for complex services:
# app/config/config.yml
doctrine:
orm:
cache: [db, default]
This cache can also be used for third-party bundles:
# app/config/config.yml
liip_imagine:
cache: true # or false, or 'db', or ['db', 'default'], etc.
Thoughts? Comments? Other ideas?