nickjbedford/tagcache
Composer 安装命令:
composer require nickjbedford/tagcache
包简介
Provides file-based caching of generated/fetched data or text using keys based on objects, allowing for unified key naming conventions and efficient clearing of caches.
关键字:
README 文档
README
TagCache is a PHP data and text file-based caching library designed to make it simple to generate and store serialized data and text/HTML content for highly efficient retrieval when paired with high-performance memory-cached file systems such as on Linux. Cache retrieval times (including deserialization) can be submillisecond on modern SSD-based infrastructure using native file systems.
Cache names are created based on tagged keys, such as object type/ID or date ranges, making it easy to manage and invalidate caches as needed. Symbolic links are used to create a tag-based directory structure for easy clearing of canonical cache files.
Cache keys are created from a specific name combined with tags againsts objects or dates related to that cache. When an object is updated, all canonical cache files related to that object can be cleared easily via the symlink directory structure.
For example:
A cache key named "row-listing" related to "order #123" and "account #21" would create
the canonical cache file of feb9ed37caf09e97ec0f49f65fccad64.cache which is typically
stored as its md5 hash :
cache-dir/
└── cache/
└── en/
└── feb9ed37caf09e97ec0f49f65fccad64.cache
└── tags/
└── en/
└── order/
└── 123/
└── feb9ed37caf09e97ec0f49f65fccad64 [symlink] -> <cache-dir>/cache/en/feb9ed37caf09e97ec0f49f65fccad64.cache
└── account/
└── 21/
└── feb9ed37caf09e97ec0f49f65fccad64 [symlink] -> <cache-dir>/cache/en/feb9ed37caf09e97ec0f49f65fccad64.cache
Performance Characteristics
The following performance benchmarks are based on tests run on an 2020 iMac Retina 5K with the following specifications:
Development Workstation
- macOS Sequoia 15.7 (24G222)
- 3.3GHz Intel Core i5 6-Core processor
- Apple 1TB SSD (APPLE SSD AP1024N Media)
- Benchmarked at ~2.5 GB/s read and write speed
Amazon EC2 Web Server
- Ubuntu Linux 24.04.3 LTS
- Amazon EC2
t3.smallinstance - 2 vCPUs, 2 GiB memory
- EBS gp3 volume SSD
- 3000 IOPS
- 125 MiB/s
Cache Retrieval (Hit)
TagCache is optimized for read-heavy workloads where cache retrieval speed is critical. By leveraging modern file systems and fast storage, the cache retrieval process involves the following steps:
- Construct the cache key declaration.
- Generate the canonical MD5 cache key and full path.
- Check if the file exists.
- Check if the existing file modification time is within the valid cache duration.
- Acquire a shared lock on the file for reading.
- Read the file contents into a
stringvariable. - Close the file and release the lock.
- Deserialize the string into an object (if required).
This entire process for a small multi-property PHP object can take as little as
20-30 microseconds (including deserialization) when the operating system has
the file cached in memory. See tests/PerformanceTests.php for benchmarks.
Cache Generation (Miss)
Cache generation introduces some overhead due to the need to create symbolic links as well as write the cache file. The process involves the following steps:
- Construct the cache key declaration.
- Generate the canonical MD5 cache key and full path.
- Acquire an exclusive lock on the file to be cached, to prevent race conditions.
- Generate and serialize the data value to be cached using the supplied generator callable.
- Write the serialized data to the cache file.
- Close the file and release the lock.
- For each tag, create the necessary directories and symbolic links to the cache file.
Despite all of these steps, cache storage and symbolic link creation can still be performed
in as low as 0.5 milliseconds (500μs) for a small multi-property PHP object on modern SSD-based
infrastructure with a modern file system. See tests/PerformanceTests.php for benchmarks.
Benchmark Results
The benchmark generates between 5000-5100 randomised cache files for testing cache hits. Each file is
then read back in a loop to measure performance. This ensures that the operating system has the
files cached in memory, simulating a real-world scenario where frequently accessed cache files
are kept in memory by the OS. See tests/PerformanceTests.php for the benchmark code.
The results are as follows:
Development Workstation
5009x cache hits took 0.163396 seconds
Microseconds per cache hit: 32.62 μs
Amazon EC2 Web Server
5061x cache hits took 0.10656 seconds
Microseconds per cache hit: 21.055 μs
File Locking
TagCache uses file locking to ensure data integrity during cache writes. Shared locks are used for reading cache files, while exclusive locks are used for writing. This prevents race conditions and ensures that cache files are not corrupted during concurrent access. It also ensures that multiple processes do not attempt to generate the same cache simultaneously, which could lead to redundant work and potential inconsistencies.
Lock acquisition is performed using a non-blocking call to allow for a default timeout period of 30 seconds. This means that if a process cannot acquire the lock within this timeframe, it will fail gracefully rather than hanging indefinitely.
nickjbedford/tagcache 适用场景与选型建议
nickjbedford/tagcache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「performance」 「php」 「cache」 「caching」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nickjbedford/tagcache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nickjbedford/tagcache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nickjbedford/tagcache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
g4 application profiler package
repository php library
CSS/Javascript Minificator, Compressor and Concatenator for TYPO3 - highly configurable frontend asset optimization for CSS/JS merging, minification and compression with optional body parsing, async/defer loading, inline output, data-ignore exclusions, SRI integrity validation/calculation, external
WordPress mu-plugin to remove jQuery Migrate from the list of jQuery dependencies and to allow jQuery to enqueue before </body> instead of in the <head>.
Create link to static resources with cache-breaking segment based on md5 of the file
Laravel 5 - Repositories to the database layer
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-14