2

I've been trying to install the cache/cache-bundle recipe into my symfony4 flex-configured project, but to no avail. I execute:

composer require cache/cache-bundle

And this is what I got on the shell:

Capture of recipe cache-bundle install result on shell

Installing the cache-bundle generates a cache.yml file under config/packages/cache.yml, and its default content is:

cache:
    session:
       enabled: "%env(bool:SESSION_CACHE_ENABLED)%"
       service_id: "cache.provider.default"
       use_tagging: true
       ttl: 7200
    router:
       enabled: "%env(bool:ROUTER_CACHE_ENABLED)%"
       service_id: "cache.provider.default"
       ttl: 86400
    logging:
       enabled: "%env(bool:APP_DEBUG)%"
       logger: "logger"
       level: "info"

The problematic line is the first "enabled" one. For some reason, Symfony or composer doesn't like that %env(bool:SESSION_CACHE_ENABLED)% and returns that error message:

Invalid type for path "cache.session.enabled". Expected boolean, but got string.

SESSION_CACHE_ENABLED is a value introduced in the .env file of the project by composer in a block like this.

###> cache/cache-bundle ###
SESSION_CACHE_ENABLED=true
ROUTER_CACHE_ENABLED=false
###< cache/cache-bundle ###

Then, the question is if someone else has "suffered" this problem and found a fix or workaround to make this config work. My objective is to use this dependency in my mock project to cache arrays in memory to use them as a fake DB system.

I thought to open an issue about this, but since I'm not sure if this is a Simfony issue or just a problem in the recipe I preferred to ask here first.

And for the sake of completion, here's the list of current dependencies already in my project.

"require": {
    "php": "^7.1.3",
    "easycorp/easy-log-handler": "^1.0",
    "friendsofsymfony/rest-bundle": "^2.3",
    "hermes/bridge/common": "dev-master",
    "hermes/common": "dev-master",
    "jms/serializer": "^1.10",
    "jms/serializer-bundle": "^2.3",
    "ramsey/uuid": "^3.7",
    "sensio/framework-extra-bundle": "^5.1",
    "symfony/cache": "^4.0",
    "symfony/console": "^4.0",
    "symfony/framework-bundle": "^4.0",
    "symfony/http-foundation": "^4.0",
    "symfony/monolog-bundle": "^3.1",
    "symfony/stopwatch": "^4.0",
    "symfony/web-server-bundle": "^4.0",
    "symfony/yaml": "^4.0"
},
"require-dev": {
    "symfony/flex": "^1.0",
    "symfony/dotenv": "^4.0"
}

I've seen questions about issues regarding booleans in dotenv files, but nothing conclusive for this question, I'm afraid.

3d0
  • 23
  • 6
  • I created a fresh skeleton and then required only the cache bundle and got the same error. I suspect it is a cache bundle issue. The cache.yaml logger section has an 'info' field which is not defined by the configuration. I suspect the bundle is out of date. Maybe check for issues on github and open a new one if necessary. The fact that you have symfony/flex in the require-dev section of composer.json also seems a bit strange. – Cerad Jan 26 '18 at 13:54
  • The first time I noticed the flex dependency in that section I thought the same thing about it, @Cerad, althought it hasn't given me any trouble yet. By the way, I've opened an issue about this matter in the [php-cache project on github](https://github.com/php-cache/issues/issues/124). – 3d0 Jan 26 '18 at 16:12
  • I'll answer here the downvoted question below: Yes, I got rid off the quotes and it failed giving this error: `The reserved indicator "%" cannot start a plain scalar; you need to quote the scalar at line 3[...]` So no, you can't get rid of the quotes. – 3d0 Jan 26 '18 at 16:15

1 Answers1

-3

Have you tried to get rid off the quotes around "%env(bool:SESSION_CACHE_ENABLED)%"?

Romain biard
  • 186
  • 9
  • Answering a question with a question is frowned upon and often leads to down votes. I might add that in many cases the cliche "there are no stupid questions" is often incorrect. – Cerad Jan 26 '18 at 13:48
  • Sorry, I just couldn't comment your question, otherwise I would have done so. Considering the error message you got, "Invalid type for path "cache.session.enabled". Expected boolean, but got string." it still seems to me that these quotes might be the problem, but disregard my "question" if you think it's irrelevant... – Romain biard Jan 26 '18 at 14:03
  • Not my question but, as requested, I have gone ahead and down voted it for you. – Cerad Jan 26 '18 at 14:08