PHPackages                             mmamedov/page-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. mmamedov/page-cache

ActiveLibrary[Caching](/categories/caching)

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.

v3.0.0(3mo ago)7913.3k—9.2%25[6 issues](https://github.com/mmamedov/page-cache/issues)[2 PRs](https://github.com/mmamedov/page-cache/pulls)1MITPHPPHP &gt;=8.1CI passing

Since Apr 17Pushed 3mo ago5 watchersCompare

[ Source](https://github.com/mmamedov/page-cache)[ Packagist](https://packagist.org/packages/mmamedov/page-cache)[ Docs](https://github.com/mmamedov/page-cache)[ RSS](/packages/mmamedov-page-cache/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (20)Versions (15)Used By (1)

[![PHP Composer](https://github.com/mmamedov/page-cache/actions/workflows/php.yml/badge.svg?branch=master)](https://github.com/mmamedov/page-cache/actions/workflows/php.yml) [![Latest Stable Version](https://camo.githubusercontent.com/6c5d01fa7d992a221f601ef93b69ca3d814b130f893534a8418b833d24d139dd/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6d616d65646f762f706167652d63616368652e737667)](https://packagist.org/packages/mmamedov/page-cache) [![License](https://camo.githubusercontent.com/d36f2153e7f2f86edb78306cc864cbf356877852f135c82290b7047af5b295cd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d6d616d65646f762f706167652d63616368652e737667)](https://packagist.org/packages/mmamedov/page-cache)

Full-page PHP Caching library
-----------------------------

[](#full-page-php-caching-library)

PageCache is a lightweight PHP library for full page cache, works out of the box with zero configuration. Use it when you need a simple yet powerful file-based PHP caching solution. Page caching for mobile devices is built-in.

Install via Composer:

```
composer require mmamedov/page-cache

```

Or add to your `composer.json` manually:

```
{
  "require": {
      "mmamedov/page-cache": "^3.0"
  }
}
```

#### Upgrading to v3.\*

[](#upgrading-to-v3)

Version 3.0 requires **PHP 8.1+** — a breaking change from v2, which supported PHP 5.6+.

- `psr/log` upgraded to `^3.0` and `psr/simple-cache` upgraded to `^3.0`. Ensure your project's PSR dependencies are compatible.
- No public API changes — existing code should work without modification.

#### Upgrading to v2.\*

[](#upgrading-to-v2)

Version 2.0 is not backwards compatible with v1.x.

- Your config file must use `return [...]` and not `$config = array(...);` like in the previous version.
- Config `expiration` setting was renamed to `cache_expiration_in_seconds`.
- Use `try/catch` to ensure proper page load in case of a PageCache error.

If you find any other notable incompatibilities please let us know and we will include them here.

No Database calls
-----------------

[](#no-database-calls)

Once a page is cached, there are no more database calls needed. Even if your page contains many database calls and complex logic, it will be executed once and cached for the period you specify.

This is a very efficient and simple method to cache your most visited dynamic pages. [Tmawto.com](https://www.tmawto.com) website is built on PageCache.

Why another PHP Caching class?
------------------------------

[](#why-another-php-caching-class)

Short answer — simplicity. If you want to include a couple of lines of code on top of your dynamic PHP pages and cache them fully, then PageCache is for you. No worrying about cache file name setup for each URL, no worries about your dynamically generated URL parameters and changing URLs. PageCache detects those changes and caches accordingly.

PageCache also detects `$_SESSION` changes and caches those pages correctly. This is useful if you have user authentication enabled on your site, and page contents change per user login while the URL remains the same.

Lots of caching solutions focus on a keyword-based approach, where you need to set up a keyword for your content (be it a full page cache, a variable, etc.). There are great packages for that approach. One could also use a more complex solution like a cache proxy (e.g. Varnish). PageCache is a simple full-page caching solution that does exactly what its name says.

How PageCache works
-------------------

[](#how-pagecache-works)

PageCache doesn't ask you for a keyword — it automatically generates one based on Strategies implementing `StrategyInterface`. You can define your own naming strategy based on your application's needs. The Strategy class is responsible for generating a unique key for the current request; the key becomes the file name for the cache file (if FileSystem storage is used).

```
