PHPackages                             nickjbedford/tagcache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. nickjbedford/tagcache

ActiveLibrary[Caching](/categories/caching)

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.

0.6.2(5mo ago)023MITPHPPHP &gt;=8.4

Since Oct 10Pushed 5mo agoCompare

[ Source](https://github.com/nickjbedford/tagcache)[ Packagist](https://packagist.org/packages/nickjbedford/tagcache)[ Docs](https://github.com/nickjbedford/tagcache)[ RSS](/packages/nickjbedford-tagcache/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (10)Used By (0)

TagCache
========

[](#tagcache)

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/en/feb9ed37caf09e97ec0f49f65fccad64.cache
        └── account/
            └── 21/
                └── feb9ed37caf09e97ec0f49f65fccad64 [symlink] -> /cache/en/feb9ed37caf09e97ec0f49f65fccad64.cache

```

Performance Characteristics
---------------------------

[](#performance-characteristics)

The following performance benchmarks are based on tests run on an 2020 iMac Retina 5K with the following specifications:

#### Development Workstation

[](#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

[](#amazon-ec2-web-server)

- Ubuntu Linux 24.04.3 LTS
- Amazon EC2 `t3.small` instance
- 2 vCPUs, 2 GiB memory
- EBS gp3 volume SSD
    - 3000 IOPS
    - 125 MiB/s

### Cache Retrieval (Hit)

[](#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:

1. Construct the cache key declaration.
2. Generate the canonical MD5 cache key and full path.
3. Check if the file exists.
4. Check if the existing file modification time is within the valid cache duration.
5. Acquire a shared lock on the file for reading.
6. Read the file contents into a `string` variable.
7. Close the file and release the lock.
8. 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-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:

1. Construct the cache key declaration.
2. Generate the canonical MD5 cache key and full path.
3. Acquire an exclusive lock on the file to be cached, to prevent race conditions.
4. Generate and serialize the data value to be cached using the supplied generator callable.
5. Write the serialized data to the cache file.
6. Close the file and release the lock.
7. 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

[](#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

[](#development-workstation-1)

```
5009x cache hits took 0.163396 seconds
Microseconds per cache hit: 32.62 μs

```

#### Amazon EC2 Web Server

[](#amazon-ec2-web-server-1)

```
5061x cache hits took 0.10656 seconds
Microseconds per cache hit: 21.055 μs

```

### File Locking

[](#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.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Recently: every ~23 days

Total

9

Last Release

169d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10795658?v=4)[Nick Bedford](/maintainers/nickjbedford)[@nickjbedford](https://github.com/nickjbedford)

---

Top Contributors

[![nickjbedford](https://avatars.githubusercontent.com/u/10795658?v=4)](https://github.com/nickjbedford "nickjbedford (3 commits)")

---

Tags

phpperformancecachecaching

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nickjbedford-tagcache/health.svg)

```
[![Health](https://phpackages.com/badges/nickjbedford-tagcache/health.svg)](https://phpackages.com/packages/nickjbedford-tagcache)
```

###  Alternatives

[alekseykorzun/memcached-wrapper-php

Optimized PHP 5 wrapper for Memcached extension that supports dog-piling, igbinary and local storage

2988.9k1](/packages/alekseykorzun-memcached-wrapper-php)[voku/simple-cache

Simple Cache library

332.7M10](/packages/voku-simple-cache)[silverstripe/staticpublishqueue

Static publishing queue to create static versions of pages for enhanced performance and security

44140.1k6](/packages/silverstripe-staticpublishqueue)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15195.9k7](/packages/rapidwebltd-rw-file-cache)[dereuromark/cakephp-cache

A CakePHP plugin for view caching with configurable strategies

3341.5k1](/packages/dereuromark-cakephp-cache)[tractorcow/silverstripe-dynamiccache

FORK OF Silverstripe module for simple on the fly caching of dynamic content

3816.0k2](/packages/tractorcow-silverstripe-dynamiccache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
