PHPackages                             yurikzt/html-cache-page-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. yurikzt/html-cache-page-bundle

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

yurikzt/html-cache-page-bundle
==============================

Symfony bundle for caching HTML pages to files

1.0.0(11mo ago)02MITPHPPHP &gt;=8.1

Since Jun 11Pushed 11mo agoCompare

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

READMEChangelog (1)Dependencies (9)Versions (2)Used By (0)

HtmlCachePageBundle
===================

[](#htmlcachepagebundle)

Symfony bundle for caching HTML, JSON, and XML responses as static files. Supports flexible rule-based configuration, auto-cleaning, and CLI tools.

📦 Installation
--------------

[](#-installation)

```
composer require yurikzt/html-cache-page-bundle
```

⚙️ Configuration
----------------

[](#️-configuration)

After installation, create a config file: `config/packages/html_cache_page.yaml`

```
html_cache_page:
    enabled: true
    ttl: 3600
    cache_dir: '%kernel.project_dir%/public/cache'

    cacheable_content_types:
        - 'text/html'
        - 'application/json'
        - 'application/xml'
        - 'text/xml'

    cache_rules:
        - pattern: '/blog/*'
          methods: ['GET']
        - pattern: '#^/api/products/\d+$#'
          methods: ['GET']
          parameters:
            format: ['json', 'xml']

    exclude_rules:
        - pattern: '/admin/*'
        - pattern: '/api/auth/*'

    logging:
        enabled: true
        driver: symfony
        logger_service: null
```

🚀 Usage
-------

[](#-usage)

### Automatic Caching

[](#automatic-caching)

All HTTP 200 responses that match the cache rules will be saved as files.

### Clearing Cache Programmatically

[](#clearing-cache-programmatically)

```
use Yurikzt\HtmlCachePageBundle\Service\CacheCleaner;

class MyController
{
    public function __construct(private CacheCleaner $cacheCleaner) {}

    public function clearCache(): JsonResponse
    {
        $this->cacheCleaner->clearAll();
        $this->cacheCleaner->clearByPattern('/blog/*');
        $this->cacheCleaner->clearByUrl('/blog/my-post');
        $this->cacheCleaner->clearExpired();

        $stats = $this->cacheCleaner->getStats();

        return new JsonResponse(['stats' => $stats]);
    }
}
```

### Console Commands

[](#console-commands)

```
bin/console html-cache-page:clear --stats
bin/console html-cache-page:clear
bin/console html-cache-page:clear "/blog/*"
bin/console html-cache-page:clear "#^/product/\d+$#"
bin/console html-cache-page:clear --url="/blog/abc"
bin/console html-cache-page:clear --expired
```

🗂 Cache File Structure
----------------------

[](#-cache-file-structure)

- `/blog/post-1` → `public/cache/blog/post-1/index.html`
- `/` → `public/cache/index.html`
- `/api/products/1.json` → `public/cache/api/products/1.json`
- Metadata: `.meta` file alongside each cache file.

```
{
    "created_at": 1640995200,
    "ttl": 3600,
    "content_type": "text/html",
    "status_code": 200
}
```

🧠 Rule Options
--------------

[](#-rule-options)

### Pattern Types

[](#pattern-types)

- Wildcard: `/blog/*`
- Regex: `#^/product/\d+$#`

### Query Parameters

[](#query-parameters)

```
parameters:
    q: true
    category: false
    sort: ['name', 'date']
    limit: '10'
```

📥 HTTP Headers
--------------

[](#-http-headers)

Bundle adds a header: `X-Cache-Status: HIT|MISS`

📁 Web Server Configuration
--------------------------

[](#-web-server-configuration)

### ✅ Nginx

[](#-nginx)

```
location ~* ^/cache/(.*)$ {
    try_files $uri =404;
    access_log off;
    expires 1h;
}

location / {
    try_files $uri $uri/ @cached;
}

location @cached {
    set $cached_file "/cache$uri/index.html";
    if (!-f $document_root$cached_file) {
        set $cached_file "/cache$uri";
    }

    try_files $cached_file @symfony;
}

location @symfony {
    try_files /index.php =404;
}

location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param HTTPS off;
}
```

### ✅ Apache

[](#-apache)

```

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI}/index.html -f
    RewriteRule ^ cache%{REQUEST_URI}/index.html [L]

    RewriteCond %{DOCUMENT_ROOT}/cache%{REQUEST_URI} -f
    RewriteRule ^ cache%{REQUEST_URI} [L]

    RewriteRule ^ index.php [L]

```

✅ Requirements
--------------

[](#-requirements)

- PHP 8.1+
- Symfony 6.0+

📄 License
---------

[](#-license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance52

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

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

Unknown

Total

1

Last Release

335d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/450a1617e2057a73b72b623d6fd7177b66ca1605026d6cfc318d9ddbe789177d?d=identicon)[yurikzt](/maintainers/yurikzt)

---

Top Contributors

[![yurikzt](https://avatars.githubusercontent.com/u/16242642?v=4)](https://github.com/yurikzt "yurikzt (1 commits)")

### Embed Badge

![Health badge](/badges/yurikzt-html-cache-page-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/yurikzt-html-cache-page-bundle/health.svg)](https://phpackages.com/packages/yurikzt-html-cache-page-bundle)
```

###  Alternatives

[sylius/sylius

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

8.4k5.6M651](/packages/sylius-sylius)[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k12.4M193](/packages/simplesamlphp-simplesamlphp)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[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.4k](/packages/contao-core-bundle)

PHPackages © 2026

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