Symfony Cache报错Cache key ‘xxx:xxx’ contains reserved characters解决办法

今天在使用Symfony Cache时遇到一个报错:Symfony\Component\Cache\Exception\InvalidArgumentException: Cache key "xxx:xxx" contains reserved characters "{}()/\@:",经过排查发现我的缓存key带有冒号。

根据报错信息找源头,文件vendor/symfony/cache/Traits/AbstractAdapterTrait.php第396行有如下代码:

\assert('' !== CacheItem::validateKey($key));

这里有一个断言,会根据CacheItem::RESERVED_CHARACTERS(值为{}()/\@:)来判断缓存key是否合法。

通过PHP官方文档对assert的说明,发现PHP7以上版本有如下配置:

指令 默认值 可能值
zend.assertions 1 1:生成并执行代码(开发模式)
0:生成代码但在运行时跳转
-1:生成代码但在运行时跳转(生产模式)
assert.exception 0 1:断言失败时抛出,抛出提供给 exception 的对象,或未提供 exception 时抛出新的 AssertionError 对象
0:如上所述使用/生成 Throwable,但仅仅是基于该对象生成警告而不是抛出(与 PHP 5 行为兼容)

所以解决办法有两种:

  • 修改php.ini配置,将zend.assertions的值设置为0或-1

  • 去除缓存key中的特殊符号

评论

  1. 2 月前
    2024-2-29 13:20:12

    Your blog post had me hooked from the first sentence.

  2. 3 周前
    2024-4-06 0:30:03

    You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!

  3. 3 周前
    2024-4-06 16:51:09

    For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.

  4. 3 周前
    2024-4-07 15:01:37

    This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!

  5. 3 周前
    2024-4-09 4:25:11

    I just like the helpful information you provide in your articles

  6. 3 周前
    2024-4-09 17:12:57

    For the reason that the admin of this site is working, no uncertainty very quickly it will be renowned, due to its quality contents.

  7. 3 周前
    2024-4-09 21:22:01

    There is definately a lot to find out about this subject. I like all the points you made

  8. 2 周前
    2024-4-16 9:35:15

    There is definately a lot to find out about this subject. I like all the points you made

  9. 1 周前
    2024-4-18 22:27:51

    Awesome! Its genuinely remarkable post, I have got much clear idea regarding from this post

  10. 1 周前
    2024-4-21 7:20:46

    This is my first time pay a quick visit at here and i am really happy to read everthing at one place

  11. 5 天前
    2024-4-23 1:03:53

    Great information shared.. really enjoyed reading this post thank you author for sharing this post .. appreciated

  12. 5 天前
    2024-4-23 16:02:04

    I appreciate you sharing this blog post. Thanks Again. Cool.

  13. 5 天前
    2024-4-23 22:37:58

    Awesome! Its genuinely remarkable post, I have got much clear idea regarding from this post

  14. 5 天前
    2024-4-24 0:47:51

    This is really interesting, You’re a very skilled blogger. I’ve joined your feed and look forward to seeking more of your magnificent post. Also, I’ve shared your site in my social networks!

  15. 4 天前
    2024-4-24 20:40:26

    Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.

  16. 3 天前
    2024-4-25 3:33:57

    I appreciate you sharing this blog post. Thanks Again. Cool.

  17. 3 天前
    2024-4-25 10:07:34

    Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇