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

ActiveLibrary[Caching](/categories/caching)

initphp/cache
=============

PSR-16 is a simple caching library that uses the Simple Cache interface.

0.1(4y ago)21041MITPHPPHP &gt;=5.6

Since Mar 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/InitPHP/Cache)[ Packagist](https://packagist.org/packages/initphp/cache)[ RSS](/packages/initphp-cache/feed)WikiDiscussions main Synced 1mo ago

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

InitPHP Cache
=============

[](#initphp-cache)

PSR-16 is a simple caching library that uses the Simple Cache interface.

[![Latest Stable Version](https://camo.githubusercontent.com/8200496604126a9df21d4c86cfd89608fe2d3f162fa4629f31e9b1e5465af32c/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f76)](https://packagist.org/packages/initphp/cache) [![Total Downloads](https://camo.githubusercontent.com/d096c45c535c6361c357389522fb2c583810c9fbebf6dee878da16e65a1975a9/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f646f776e6c6f616473)](https://packagist.org/packages/initphp/cache) [![Latest Unstable Version](https://camo.githubusercontent.com/c5278207958ec50a4e5e1986bd3a3659e7f62c3754bb86de531beae1049bbd28/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f762f756e737461626c65)](https://packagist.org/packages/initphp/cache) [![License](https://camo.githubusercontent.com/170a9fc28ba049d125f182195f0fc81f3ee50f5a9984ebc40f0218d908613430/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f6c6963656e7365)](https://packagist.org/packages/initphp/cache) [![PHP Version Require](https://camo.githubusercontent.com/e7c2497129c9dc9c95da765be7a68591766310e9cfa27897e009cfae955cf1b4/687474703a2f2f706f7365722e707567782e6f72672f696e69747068702f63616368652f726571756972652f706870)](https://packagist.org/packages/initphp/cache)

Requirements
------------

[](#requirements)

- PHP 5.6 or higher
- [PSR-16 Simple Cache Interface](https://www.php-fig.org/psr/psr-16/)

Depending on the handler you will use, it may need PHP extensions.

- Redis
- PDO
- Wincache
- Memcache or Memcached

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

[](#installation)

```
composer require initphp/cache

```

Usage
-----

[](#usage)

```
require_once "../vendor/autoload.php";
use \InitPHP\Cache\Cache;

$cache = Cache::create(\InitPHP\Cache\Handler\File::class, [
    'path'      => __DIR__ . '/Cache/';
]);

if(($posts = $cache->get('posts', null)) === null){
    $posts = [
        ['id' => '12', 'title' => 'Post 12 Title', 'content' => 'Post 12 Content'],
        ['id' => '15', 'title' => 'Post 15 Title', 'content' => 'Post 15 Content'],
        ['id' => '18', 'title' => 'Post 18 Title', 'content' => 'Post 18 Content']
    ];
    $cache->set('posts', $posts, 120);
}

echo ''; print_r($posts) echo '';
```

Configuration and Options
-------------------------

[](#configuration-and-options)

### `\InitPHP\Cache\Handler\File::class`

[](#initphpcachehandlerfileclass)

```
$options = [
    'prefix'    => 'cache_',
    'mode'      => 0640,
];
```

### `\InitPHP\Cache\Handler\Memcache::class`

[](#initphpcachehandlermemcacheclass)

```
$options = [
    'prefix'    => 'cache_',
    'host'          => '127.0.0.1',
    'port'          => 11211,
    'weight'        => 1,
    'raw'           => false,
    'default_ttl'   => 60,
];
```

### `\InitPHP\Cache\Handler\PDO::class`

[](#initphpcachehandlerpdoclass)

```
$options = [
    'prefix'    => 'cache_',
    'dsn'           => 'mysql:host=localhost;dbname=test',
    'username'      => null,
    'password'      => null,
    'charset'       => 'utf8mb4',
    'collation'     => 'utf8mb4_general_ci',
    'table'         => 'cache'
];
```

*Below is a sample cache table creation query for MySQL.*

```
CREATE TABLE `cache` (
    `name` VARCHAR(255) NOT NULL,
    `ttl` INT(11) NULL DEFAULT NULL,
    `data` TEXT NOT NULL,
    UNIQUE  (`name`)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_general_ci;
```

### `\InitPHP\Cache\Handler\Redis::class`

[](#initphpcachehandlerredisclass)

```
$options = [
    'prefix'    => 'cache_',
    'host'      => '127.0.0.1',
    'password'  => null,
    'port'      => 6379,
    'timeout'   => 0,
    'database'  => 0
];
```

### `\InitPHP\Cache\Handler\Wincache::class`

[](#initphpcachehandlerwincacheclass)

```
$options = [
    'prefix'    => 'cache_', // Cache Name Prefix
    'default_ttl'   => 60, // Used if ttl is NULL or not specified.
];
```

Credits
-------

[](#credits)

- [Muhammet ŞAFAK](https://www.muhammetsafak.com.tr) &lt;&gt;

License
-------

[](#license)

Copyright © 2022 [MIT License](./LICENSE)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

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

1523d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b6b34f3ac8938d8ee52ba3bd260680855dc5715c7b2929d9380de30d15a67dd?d=identicon)[muhammetsafak](/maintainers/muhammetsafak)

---

Tags

cachefile-cachememcachememcachedpdo-cachephppsr-16redisredis-cachesimple-cachewincachephpcachecachingsimple-cachepsr-16

### Embed Badge

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

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

###  Alternatives

[psr/simple-cache

Common interfaces for simple caching

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

Simple Cache library

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

Simple cache abstraction layer implementing PSR-16

541.2M3](/packages/sabre-cache)

PHPackages © 2026

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