Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[RFC] The new Cache component should be a centerpiece feature of Symfony #17537

Copy link
Copy link
Closed
@javiereguiluz

Description

@javiereguiluz
Issue body actions

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:

  1. A boolean, to enable or disable the cache. If true, the default 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
  1. 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
  1. 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    CacheRFCRFC = Request For Comments (proposals about features that you want to be discussed)RFC = Request For Comments (proposals about features that you want to be discussed)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.