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.

v2.0.4(8y ago)7912.7k↓50%25[2 PRs](https://github.com/mmamedov/page-cache/pulls)1MITPHPPHP &gt;=5.6.0

Since Apr 17Pushed 5y 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 1mo ago

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

[![Build Status](https://camo.githubusercontent.com/183b2a1dd6b95a55b51c86491740495a5691b5618a2fb59bd947a80502dd41b3/68747470733a2f2f7472617669732d63692e6f72672f6d6d616d65646f762f706167652d63616368652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mmamedov/page-cache) [![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 PHP PageCache and start caching your PHP's browser output code using Composer:

```
composer require mmamedov/page-cache

```

Or manually add to your composer.json file:

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

Once PageCache is installed, include Composer's autoload.php file, or implement your own autoloader. Composer autoloader is recommended.

Do not use `master` branch, as it may contain unstable code, use versioned branches instead.

#### Upgrading to to v2.\*

[](#upgrading-to-to-v2)

Version 2.0 is not backwards compatible with versions starting with v1.0. Version 2.0 introduces new features and code was refactored to enable us deliver more features.

When upgrading to version 2.0, please note the followings:

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

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

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

[](#no-database-calls)

Once 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 period you specify. No more overload!

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, and is very fast.

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

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

Short answer - simplicity. If you want to include a couple lines of code on top of your dynamic PHP pages and be able to 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 changed 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 URL remains the same.

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

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

[](#how-pagecache-works)

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

```
