PHPackages                             tourze/symfony-cache-hotkey-bundle - 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. tourze/symfony-cache-hotkey-bundle

ActiveSymfony-bundle[Caching](/categories/caching)

tourze/symfony-cache-hotkey-bundle
==================================

自动扩展Cache服务

1.0.1(4mo ago)02471MITPHPCI passing

Since Mar 27Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/symfony-cache-hotkey-bundle)[ Packagist](https://packagist.org/packages/tourze/symfony-cache-hotkey-bundle)[ RSS](/packages/tourze-symfony-cache-hotkey-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (18)Versions (7)Used By (1)

Symfony Cache HotKey Bundle
===========================

[](#symfony-cache-hotkey-bundle)

[![PHP Version](https://camo.githubusercontent.com/6b84e9311750c972da98b6d521269a76c32b8928b672000d4a8c5dd7ac866d09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344382e312d626c75652e737667)](https://www.php.net/)
[![Symfony Version](https://camo.githubusercontent.com/5fb0df181d5178dc14c12d2fdf08dc54ef020875d3be871a95b1161e294bcf43/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d253345253344362e342d677265656e2e737667)](https://symfony.com/)
[![License](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)
\[[![Build Status](https://github.com/tourze/php-monorepo/workflows/CI/badge.svg)](https://github.com/tourze/php-monorepo/workflows/CI/badge.svg)\] ()
\[[![Coverage Status](https://camo.githubusercontent.com/597d3736c612eb152d4c13a37f4e87afd6af836788df1857d930b70903f9553d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f62616467652e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/597d3736c612eb152d4c13a37f4e87afd6af836788df1857d930b70903f9553d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746f75727a652f7068702d6d6f6e6f7265706f2f62616467652e7376673f6272616e63683d6d6173746572)\] ()

[English](README.md) | [中文](README.zh-CN.md)

A Symfony Bundle designed to solve cache hotkey issues by automatically distributing hot keys across multiple sub-keys, effectively preventing a single cache node from being overloaded.

---

Features
--------

[](#features)

- Automatically detects hot keys (keys starting with `hotkey_`)
- Replicates hot key content to multiple sub-keys for load balancing
- Randomly selects a sub-key for reads
- Supports cache size monitoring and alerting
- Supports cache tag invalidation logging

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP 8.1 or higher
- Symfony 6.4 or higher
- PSR-3 Logger
- Symfony Cache component

### Using Composer

[](#using-composer)

```
composer require tourze/symfony-cache-hotkey-bundle
```

Quick Start
-----------

[](#quick-start)

### Bundle Registration

[](#bundle-registration)

Add the bundle to your `config/bundles.php`:

```
return [
    // ... other bundles
    Tourze\Symfony\CacheHotKey\CacheHotKeyBundle::class => ['all' => true],
];
```

### Marking a Hot Key

[](#marking-a-hot-key)

Simply add the `hotkey_` prefix to your cache key:

```
// Normal cache usage
$cache->get('normal_key', fn() => 'value');

// Hot key cache usage
$cache->get('hotkey_popular_data', fn() => 'value');
```

This bundle will automatically:

1. Replicate the hot key content to 10 sub-keys (`hotkey_popular_data_0_split` to `hotkey_popular_data_9_split`)
2. Randomly select a sub-key when reading
3. Clean up all sub-keys when the main key is deleted

Configuration
-------------

[](#configuration)

### Main Configuration (Environment Variables)

[](#main-configuration-environment-variables)

```
CACHE_MARSHALLER_WARNING_VALUE_SIZE=1048576 # Cache serialization warning threshold (bytes)
CACHE_MARSHALLER_WARNING_DEMO_SIZE=400      # Cache content preview size (bytes)
CACHE_INVALIDATE_TAG_LOG=false              # Enable cache tag invalidation logging
```

Advanced Usage
--------------

[](#advanced-usage)

### Cache Tag Invalidation

[](#cache-tag-invalidation)

- Supports cache tag invalidation with optional logging (`CACHE_INVALIDATE_TAG_LOG`)
- Automatically logs a warning if cache value size exceeds threshold, helping you optimize data structures

### Performance Tips

[](#performance-tips)

- For high concurrency scenarios, only use the `hotkey_` prefix for truly hot data to avoid unnecessary sharding
- You can customize the number of shards by adjusting the `MAX_KEY` constant

Contributing
------------

[](#contributing)

Issues and PRs are welcome. Please follow PSR coding standards and ensure PHPUnit tests pass before submitting.

License
-------

[](#license)

MIT License © Tourze

Changelog
---------

[](#changelog)

See [Releases](https://github.com/tourze/symfony-cache-hotkey-bundle/releases) for details

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance74

Regular maintenance activity

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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 ~53 days

Recently: every ~67 days

Total

6

Last Release

143d ago

Major Versions

0.0.4 → 1.0.02025-11-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-symfony-cache-hotkey-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-symfony-cache-hotkey-bundle/health.svg)](https://phpackages.com/packages/tourze-symfony-cache-hotkey-bundle)
```

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)

PHPackages © 2026

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