PHPackages                             vakata/router-cached - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. vakata/router-cached

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

vakata/router-cached
====================

A simple request router with cached

1.0.1(9y ago)012MITPHPPHP &gt;=5.4.0

Since Dec 10Pushed 9y ago1 watchersCompare

[ Source](https://github.com/vakata/router-cached)[ Packagist](https://packagist.org/packages/vakata/router-cached)[ Docs](https://github.com/vakata/router-cached)[ RSS](/packages/vakata-router-cached/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (3)Used By (0)

routerCached
============

[](#routercached)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ca08f44e08fc2bd10ea7d83b374c19d837c98a7a05977ed1d84a209be9111836/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76616b6174612f726f757465722d6361636865642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/vakata/router-cached)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/88de2ccd92dcee96174889f3ad0bb236351f0cab42be2396ff9d7a0cac563331/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f76616b6174612f726f757465722d6361636865642f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/vakata/router-cached)[![Code Climate](https://camo.githubusercontent.com/ed5f641c0af80b7ead1dafb6a7cae163447ff07101f6fcf2e608db5e888e6323/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f6769746875622f76616b6174612f726f757465724361636865642e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/vakata/routerCached)[![Tests Coverage](https://camo.githubusercontent.com/5531e8a3cf69f7ff6f3a4b92fedb0b1ebf3794ddf6c3f1e2e7c06153deec0036/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636c696d6174652f636f7665726167652f6769746875622f76616b6174612f726f757465724361636865642e7376673f7374796c653d666c61742d737175617265)](https://codeclimate.com/github/vakata/routerCached)

A simple request router with cache.

Install
-------

[](#install)

Via Composer

```
$ composer require vakata/router-cached
```

Usage
-----

[](#usage)

```
// Usage is the same as with the non-cached router
// you only need to supply a class implementing the \vakata\cache\CacheInterface
$router = new \vakata\routerCached\RouterCached(
    new \vakata\cache\Filecache(__DIR__), // where will cached pages be stored
    60, // cache validity in seconds - by default it is 1440 seconds
    function ($request, $verb) { // return a key for each request
        return md5($verb . ' ' . $request); // this is the default
    },
    [ 'GET', 'POST' ], // which verbs to cache
    'routeCache' // a namespace (allowing easy clearing of all cached routes)
);

// everything else is exactly the same as with the non-caching router:
$router
    ->get('/', function () { echo 'homepage'; })
    ->get('/profile', function () { echo 'user profile'; })
    ->with('/books/') // specify a prefix for all future routes
        ->get('read/{i:id}', function ($matches) {
            // this method uses a named placeholder
            // provided the user visits /books/read/10 matches will contain:
            var_dump($matches); // 0 => books, 1 => read, 2 => 10, id => 10
            // placeholders are wrapped in curly braces {...} and can be:
            //  - i - an integer
            //  - a - any letter (a-z)
            //  - h - any letter or integer
            //  - * - anything (up to the next slash (/))
            //  - ** - anything (to the end of the URL)

            // placeholders can be named too by using the syntax:
            // {placeholder:name}

            // placeholders can also be optional
            // {?optional}
        })
        // for advanced users - you can use any regex as a placeholder:
        ->get('{(delete|update):action}/{(\d+):id}', function ($matches) { })
        // you can also use any HTTP verb
        ->post('delete/{i:id}', function ($matches) { })
    // here is how you reset the prefix
    ->with('')
        // you can also bind multiple HTTP verbs in one go
        ->add(['GET', 'HEAD'], '/path', function () { })
    // you can also use with() statements to execute some code if the begging of the URL is a match to the prefix
    ->with('user', function () { echo 1; })
        ->get('view', function () { /* 1 will be echoed */ })
        ->post('chat', function () { /* 1 will be echoed */ });

// there is no need to chain the method calls - this works too:
$router->post('123', function () { });
$router->post('456', function () { });

// you finally run the router
try {
    $router->run($_SERVER['REQUEST_URI'], $_SERVER['REQUEST_METHOD']);
} catch (\vakata\router\RouterException $e) {
    // thrown if no matching route is found
}
```

Read more in the [API docs](docs/README.md)

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [vakata](https://github.com/vakata)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

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

Total

2

Last Release

3534d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/146052?v=4)[Ivan Bozhanov](/maintainers/vakata)[@vakata](https://github.com/vakata)

---

Top Contributors

[![vakata](https://avatars.githubusercontent.com/u/146052?v=4)](https://github.com/vakata "vakata (10 commits)")

---

Tags

vakatarouterCached

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/vakata-router-cached/health.svg)

```
[![Health](https://phpackages.com/badges/vakata-router-cached/health.svg)](https://phpackages.com/packages/vakata-router-cached)
```

###  Alternatives

[vakata/asn1

An ASN1 encoder / decoder

1628.0k3](/packages/vakata-asn1)

PHPackages © 2026

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