定制 krisell/laravel-translation-json-cache 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krisell/laravel-translation-json-cache

Composer 安装命令:

composer require krisell/laravel-translation-json-cache

包简介

Caches translation JSON files for faster access.

README 文档

README

When using the .json option for translations, the json-file is read and parsed for every request. This package provides an artisan command to cache the parsed data as a php-file, pretty much the same was as routes and configs can be cached. This gives a performance boost since no JSON-parsing has to be done and the opcache can be used. The actual performance boost depends on the size of the translation file and the disk speed, see below.

Installation

composer require krisell/laravel-translation-json-cache

The package is auto-registered.

Usage

To cache all translation JSON-files (in resources/lang), run the following artisan command:

php artisan translation-json:cache

If your json-files change, you need to run the command again for the changes to take effect.

You may also clear the cached files using the following command

php artisan translation-json:clear

Run translation-json:cache during deployment in the same way you run route:cache and config:cache.

The cached files are stored in the bootstrap/cache directory and are named translation-{$locale}.php.

Performance boost

On a Macbook Pro 2018 (2.6 GHz i7), using Laravel Valet, and having a JSON translation file of 1500 strings (real strings of varying length), the first call to __("A") during a request takes about 1.2 ms. Enabling this package and the same call takes 0.08 ms, i.e. the actual performance boost is in the order of 1 ms, which is substantial considering that a simple full request could be as fast as 10 ms.

I have been using this solution in production for a while (1500 strings for each language) and I have to say the performance boost is not really noticable there (comparing CPU graphs, which of course depends on a lot of other changes as well). The difference may be smaller since our server setup uses docker and an all in-memory disk. Please feel free to contribute with additional measurements under other circumstances or with other sizes of the JSON files.

License

The MIT License (MIT). Please see License File for more information.

Future work

I realize the JSON-option may not be the preferred one, and that most people already use php-files for storing their translation data hierachically. In that case, a similar approach could still possibly save time on parsing and traversal, but this is outside the scope of this package. Feel free to investigate this idéa further in a new package!

krisell/laravel-translation-json-cache 适用场景与选型建议

krisell/laravel-translation-json-cache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.88k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 10 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 krisell/laravel-translation-json-cache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 krisell/laravel-translation-json-cache 我们能提供哪些服务?
定制开发 / 二次开发

基于 krisell/laravel-translation-json-cache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-08