There is no problem not worth solving, and no technology not worth learning!

Practice and Analysis of Cache Tags in Laravel 6

运行程序以后,查看 GUI for Redis 中的数据结构。展开 tag 。cache:tag:theme_editor:key 的值为:s:22:"633146b13433b471207802";。其表示关联的 key 为:cache:633146b13433b471207802:standard_ref。这是标签:theme_editor 生成的结构。总计为 2 个 key

1. Now store the cached data that is tagged, and have 2 tags: THEME_EDITOR, THEME_EDITOR_RJXMAECRPPUAD4LLLJLLJLLJDOMXB47HRDVTB2VPW


return Cache::tags([
		ThemePreviewInterface::TAG_THEME_EDITOR,
		ThemePreviewInterface::TAG_THEME_EDITOR . '_' . $sessionId]
	)
	->put(ThemePreviewInterface::THEME_EDITOR_SESSION_PREFIX . $sessionId, json_encode($data), ThemePreviewInterface::TTL);


2. After running the program, check the data structure in GUI for Redis. Expand the tag. The value of cache:tag:theme_editor:key is: s:22:”633146b13433b471207802″;. It represents the associated key: cache:633146b13433b471207802:standard_ref. This is the tag: theme_editor generated structure. The total is 2 keys. as shown in Figure 1

运行程序以后,查看 GUI for Redis 中的数据结构。展开 tag 。cache:tag:theme_editor:key 的值为:s:22:"633146b13433b471207802";。其表示关联的 key 为:cache:633146b13433b471207802:standard_ref。这是标签:theme_editor 生成的结构。总计为 2 个 key
Figure 1

3. After running the program, check the data structure in GUI for Redis. Expand the tag. cache:tag:theme_editor_rjxmaecrppuad4ljlljlljdomxb47hrdvtb2vpw:key The value is: S:22:”633146b134d67627586383″;. It represents the associated key: cache:633146b134d67627586383:standard_ref. This is the structure generated by the tag: theme_editor_rjxmaecrppuad4ljlljlljdomxb47hrdvtb2vpw. The total is 2 keys. as shown in Figure 2

运行程序以后,查看 GUI for Redis 中的数据结构。展开 tag 。cache:tag:theme_editor_rjxMAeCRpPuaD4LJlljDOMXb47hRdVTb2vPW:key 的值为:s:22:"633146b134d67627586383";。其表示关联的 key 为:cache:633146b134d67627586383:standard_ref。这是标签:theme_editor_rjxMAeCRpPuaD4LJlljDOMXb47hRdVTb2vPW 生成的结构。总计为 2 个 key
Figure 2

4. The value list of the keys associated with the 2 tags is the same, and the corresponding key can be obtained :Cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:them E_EDITOR_SESSION:RJXMAECRPPUAD4LLLJLLJDOMXB47HRDVTB2VPW . as shown in Figure 3

2 个标签所关联的 key 的值列表是相同的,可得到对应的 key :cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:theme_editor_session:rjxMAeCRpPuaD4LJlljDOMXb47hRdVTb2vPW
Figure 3

5. Decide to delete cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:theme _editor_session:rjxmaecrppuad4ljlljlljdomxb47hrdvtb2vpw the corresponding cached data. Do not use the tags method. The result of the operation is False , which means that the deletion failed. as shown in Figure 4

决定删除 cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:theme_editor_session:rjxMAeCRpPuaD4LJlljDOMXb47hRdVTb2vPW 所对应的缓存数据。不使用 tags 方法。操作结果为 false ,表示删除失败
Figure 4

        $result = Cache::forget($sessionId);

        dd($result);


6. Use the tags method. The result of the operation is true , which means that the deletion was successful. as shown in Figure 5

使用 tags 方法。操作结果为 true ,表示删除成功
Figure 5

        $result = Cache::tags(ThemePreviewInterface::TAG_THEME_EDITOR . '_' . $sessionId)->flush();

        dd($result);


7. Check the data in Redis. Cache:633146b13433b471207802:The associated value list in STANDARD_REF still has 1 records, not deleted: Cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:t HEME_EDITOR_SESSION:RJXMAECRPPUAD4LLLJLLJDOMXB47HRDVTB2VPW . Key Cache:633146b134d67627586383:standard_ref has been deleted, and the key corresponding to 1 record in the associated value list in the previous one has also been deleted. in line with expectations. as shown in Figure 6

查看 Redis 中的数据。cache:633146b13433b471207802:standard_ref 中的关联的 值列表中仍然有 1 条记录,未删除:cache:327d4fd2bc91588c8a5e4c7248cf680165a2e12a:theme_editor_session:rjxMAeCRpPuaD4LJlljDOMXb47hRdVTb2vPW 。键 cache:633146b134d67627586383:standard_ref 已经被删除,之前其中的关联的 值列表中的 1 条记录所对应的 key 也已经被删除。符合预期
Figure 6

PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support

If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.

Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance

We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection

If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.

Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com

评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.