PHPackages                             aalfiann/buffer-cache - 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. aalfiann/buffer-cache

ActiveLibrary[Caching](/categories/caching)

aalfiann/buffer-cache
=====================

Cache the response page with buffer support.

1.6.0(5y ago)037MITPHPPHP &gt;=7.1

Since May 17Pushed 5y ago1 watchersCompare

[ Source](https://github.com/aalfiann/buffer-cache)[ Packagist](https://packagist.org/packages/aalfiann/buffer-cache)[ RSS](/packages/aalfiann-buffer-cache/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (9)Used By (0)

Buffer Cache
============

[](#buffer-cache)

[![Latest Stable Version](https://camo.githubusercontent.com/c5f2fa38311d386ee5cb21a88da749cab60b0dc19efb9ee723ae7211e572475c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61616c6669616e6e2f6275666665722d63616368652e737667)](https://packagist.org/packages/aalfiann/buffer-cache)[![Total Downloads](https://camo.githubusercontent.com/87b6d8efda3d0677e35b748a0c651b1db80379a5bbc99b90bae27c0ffec12064/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61616c6669616e6e2f6275666665722d63616368652e737667)](https://packagist.org/packages/aalfiann/buffer-cache)[![License](https://camo.githubusercontent.com/92716e0409c9727998cced0680aa7a298e632fbde7b2d2ecdfb0e4508101e950/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61616c6669616e6e2f6275666665722d63616368652e737667)](https://github.com/aalfiann/buffer-cache/blob/HEAD/LICENSE.md)

Cache the response page with buffer support.
Sometimes we just want to simply cache the output response page.

Dependencies
------------

[](#dependencies)

- Symfony Cache &gt;&gt; symfony/cache
- Doctrine Cache &gt;&gt; doctrine/cache

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

[](#installation)

Install this package via [Composer](https://getcomposer.org/).

```
composer require aalfiann/buffer-cache

```

- With SQLite
    Make sure your server already installed `php7-sqlite3`.
- With Redis

    ```
    composer require predis/predis

    ```

Usage
-----

[](#usage)

```
use aalfiann\BufferCache\FilesystemBufferCache;

require 'vendor/autoload.php';

// Callback to modify html source before cache
function modify($buffer) {
    // Test inject javascript
    $javascript = 'console.log("Cache was generated at '.date('Y-m-d H:i:s').'")';
    $buffer = explode('',$buffer);
    $buffer = implode($javascript.'',$buffer);
    return $buffer;
}

$cache = new FilesystemBufferCache([
    // Set ttl cache
    'ttl' => 120
]);

// Start cache
$cache->start();

// Start buffer
//$cache->startBuffer();        // without callback
$cache->startBuffer('modify');  // with callback

// Example to render page
echo '

        Test Page

    Just test to cache the response page
';

// for condition if page failed to render
//$cache->cancelBuffer();

// End cache
//$cache->end();        // without callback
$cache->end('modify');  // with callback

```

Available Constructor
---------------------

[](#available-constructor)

1. Cache with Filesystem

    ```
    use aalfiann\BufferCache\FilesystemBufferCache;
    $cache = new FilesystemBufferCache([
        // options here
    ]);

    ```
2. Cache with SQLite3

    ```
    use aalfiann\BufferCache\SQLiteBufferCache;
    $cache = new SQLiteBufferCache([
        // options here
    ]);

    ```
3. Cache with Redis

    ```
    use aalfiann\BufferCache\PredisBufferCache;
    $cache = new PredisBufferCache([
        // options here
    ]);

    ```

Options in constructor class
----------------------------

[](#options-in-constructor-class)

Here is the default options in constructor class

```
[
    'namespace' => 'page',              // Namespace for cache
    'ttl' => 18000,                     // Time to live cache
    'http_cache' => false,              // Use http cache
    'http_maxage' => 3600,              // Maxage of http cache
    'cache_empty_content' => false,     // Cache empty content
    'cache_query_param' => false,       // Allow cache for url with query parameter
    'ext' => [                          // Allow cache for url with extension
        '.htm','.html','.xhtml','.asp','.aspx','.css',
        '.php','.js','.jsp','.cfm','.md','.xml','.rss'
    ],
    'filesystem' => [                   // filesystem parameters or options
        'path' => 'cache/page'
    ],
    'sqlite3' => [                      // sqlite3 parameters or options
        'table' => 'cache',
        'path' => 'cache/page/page_cache.sqlite3'
    ],
    'predis' => [                       // predis parameters or options.
        'scheme' => 'tcp',
        'host'   => '127.0.0.1',
        'port'   => 6379
    ]
]

```

For more detail information about predis options. See .

Url page with extension
-----------------------

[](#url-page-with-extension)

This will not cache for url page with binary extension like .exe, .rar, .zip, .mp4, .mp3, etc.
You have to whitelist the extension if you want to cache.

The default extensions which is already allowed are:

```
var $ext = [
    '.htm','.html','.xhtml','.asp','.aspx','.css',
    '.php','.js','.jsp','.cfm','.md','.xml','.rss'
];

```

Example if you want to add more `.py` and `.txt`.

```
$cache->addExtension('.py');
$cache->addExtension('.txt');

```

Example if you want just allow `.js` and `.css` only.

1. By options in constructor class

    ```
    $cache = new SQLiteBufferCache([
        'ext' => ['.js', '.css']
    ]);

    ```
2. Or by properties

    ```
    $cache->ext = ['.js', '.css'];

    ```

Http Cache
----------

[](#http-cache)

This library is support http cache but inactivated by default.
If you want to use this, there is three ways :

1. By options in constructor class

    ```
    $cache = new SQLiteBufferCache([
        'http_cache' => true,
        'http_maxage' => 3600
    ]);

    ```
2. Or by function

    ```
    $cache->useHttpCache(3600);

    ```
3. Or by properties

    ```
    $cache->http_cache = true;
    $cache->http_maxage = 3600;

    ```

Note
----

[](#note)

- I only create buffer cache with using **Filesystem**, **SQLite3** and **Redis**, so contribution are welcome.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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

Recently: every ~0 days

Total

8

Last Release

2163d ago

### Community

Maintainers

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

---

Top Contributors

[![aalfiann](https://avatars.githubusercontent.com/u/9458941?v=4)](https://github.com/aalfiann "aalfiann (9 commits)")

---

Tags

buffer-cachecachepage-cacheresponse-cachesimple-cachecachesimple-cachepage cacheresponse-cachebuffer-cache

### Embed Badge

![Health badge](/badges/aalfiann-buffer-cache/health.svg)

```
[![Health](https://phpackages.com/badges/aalfiann-buffer-cache/health.svg)](https://phpackages.com/packages/aalfiann-buffer-cache)
```

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

8.1k727.3M2.1k](/packages/psr-simple-cache)[sabre/cache

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)[voku/simple-cache

Simple Cache library

322.5M7](/packages/voku-simple-cache)[mmamedov/page-cache

PageCache is a lightweight PHP library for full page cache. It uses various strategies to differentiate among separate versions of the same page.

7912.7k1](/packages/mmamedov-page-cache)

PHPackages © 2026

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